开发者

Why would webview's loadHTMLString not hit webViewDidStartLoad callback?

Background: I am developing a news reader type app native for the iPhone which displays many of the news articles as html in UIWebViews. My current goal is to have a css file in my project that can style html that is programmitically meshed up (article + comments, etc). I have done a bunch of little proof of concepts and I know that I can use <link id=\"stylesheet\" rel=\"stylesheet\" href=\"Test.css\" type=\"text/css\" /> as part of the input string to webview's loadHTMLString and achieve the result of styling the html in an expected manner, using the mainbundle's bundlepath as the baseUrl input to that function. Unfortunately, this does not work when I do this in my actual project. Note here that my issue can be reproduced with simple html.

Here's the part wh开发者_高级运维ere I scratch my head: I can use @"" as the base url and display the unstyled html as expected. But, if I use the bundlepath as the baseUrl instead, the UIWebView goes blank. Investigating further, the webViewDidStartLoad callback never hits it's breakpoint (it does in the @"" case). What would cause this not to fire? Of the 4 callbacks, the only one that fires is the shouldStartLoadWithRequest, which I return NO from. The didFailLoadWithError and the webviewDidFinishLoad are the other two.

My suspicion is that something must be wrong with the mainbundle, but I have no idea what.

I do receive this message in gdb sometimes, although this could be unrelated: void SendDelegateMessage(NSInvocation*): delegate failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode If you were not using the touch screen for this entire interval (which can prolong this wait), please file a bug.

Code Snippets: Note: the css link actually has no affect on this issue

UIWebView* contentView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.delegate = self;
NSString *htmlString = @"<html><body>Hello World</body></html>";
NSString *path = [bundle bundlePath];
NSURL *resourceBaseURL = [NSURL fileURLWithPath:path];
[contentView loadHTMLString:htmlString baseURL:resourceBaseURL];

Values at time of loadHTMLString call:

htmlString: "<html><body>Hello World</body></html>"
resourceBaseUrl: file://localhost/Users/U0107552/Library/Application%20Support/iPhone%20Simulator/3.1.3/Applications/D0EE8DA9-B156-47B3-BC53-9A731F813FB1/Test%20App.app/

The one difference that I can see between my working POC and my app is that gdb: po htmlString returns "[the above string] Current Language: auto; currently objective-c" in the POC but just the string in my app.

Sorry for the long-windedness.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜