0

I would like to load html files, which are downloaded into document folder. First page is loaded ok, but links to second page not works and images not work too. I am using this code:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *path = [documentDirectory stringByAppendingPathComponent:@"index.htm"];
NSString* htmlString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[pruvodceWebView loadHTMLString:htmlString baseURL:nil];

Is there any reason, why webview do this? Thank you

Jiri K
  • 45
  • 5

1 Answers1

2

The problem is that you have HTML source but not images Instead of

[pruvodceWebView loadHTMLString:htmlString baseURL:nil];

You should define baseURL. If your images are in documents directory

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[pruvodceWebView loadHTMLString:htmlString baseURL:baseURL];

Or provide path to images if they have relative path

[pruvodceWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString@"http://yourSiteHere.com/"]];

Check out this: Load resources from relative path using local html in uiwebview

Community
  • 1
  • 1
Injectios
  • 2,777
  • 1
  • 30
  • 50