This code fragment:
NSString *content = @"&开发者_JAVA百科lt;html><head></head><body bgcolor=#AAAAAA></body></html>";
[wv loadHTMLString:content baseURL:[NSURL URLWtihString:@""];
does not work with any other baseURL except for one written above (even with nil). This behaviour prevents me from using local data in my webViews. Can anyone be any assistance with this? In case i set any other baseURL, content is just not being loaded
Apart from suggesting what I am using in my code:
[webView loadHTMLString:[....
baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
I cannot do much. Using [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent]
is not correct, because that way you are moving upwards and outside the app bundle, but since you say you are trying many variants, I am not sure what could be.
If you want to try and troubleshoot what happens with your baseURL
, override webView:shouldStartLoadWithRequest:
and have a look at what files your web view attempts to open.
EDIT:
if you need accessing the Library folder of your app, this is the way to go (source)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];
[webView loadHTMLString:[....
baseURL:[NSURL fileURLWithPath:libraryDirectory]];
Anyway, from your comment: "they were previously downloaded by my app", you should already know how to go there... anyway, I suggest again to check what files are you trying to access in webView:shouldStartLoadWithRequest:
...
精彩评论