2

I am having a huge problem on iOS 6.

I need to display a webpage when the app starts. I use the loadHTMLString for this. On everything before iOS 6 everything works as expected, but on iOS 6, it seems to take approx. 2 minutes to load anything that is not a text. All images and so forth take each 2 minutes to load, which makes my page load in just about 8 minutes. This works real fast on iOS 5.1 and below.

Here is an issue that I found on the site that explains my issue, but doesn't have an answer : https://devforums.apple.com/message/724010

I really need an answer on this.

When I make an empty app that does just this, everything works, if I put this inside an app that does some network before it starts, the issue pops up. so this is very difficult to isolate, but as far as I can get with UIWebView, I would think the issue is related to baseURL, but that is just a feeling.

P.J
  • 6,547
  • 9
  • 44
  • 74
Trausti Thor
  • 3,722
  • 31
  • 41
  • Could you write an html file to your documents directory and then load it from there instead? – Ben Clayton Oct 05 '12 at 10:23
  • Do you think that would help ? – Trausti Thor Oct 05 '12 at 10:49
  • Yes, i think so. We load very large and complex HTML documents from there and it's very quick on iOS6 (and iOS5). – Ben Clayton Oct 05 '12 at 14:10
  • I have looked into this and perhaps this might fix the issue, but unfortunately it is impossible since the company that has the website want to be able to change the website at any time, so all logos and such could change at any time – Trausti Thor Oct 25 '12 at 14:10

2 Answers2

1

UIWebView is slightly different between iOS 5 and 6 in that the message

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

is sent to the views delegate in iOS 6 when loadHTMLString:baseURL: is called, but this is not the case in iOS 5. My delegate method is

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    [[UIApplication sharedApplication] openURL:[request URL]];
    return NO;
}

and it seems that an empty base URL caused the shared application load to barf. As this is is new for iOS 6 this seems to be the culprit, maybe you have something similar. Checking for the empty base url in the delegate method fixed my problem. It's not pretty but it worked.

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if ( [@"file:///" isEqualToString:[[request URL] absoluteString]] ) {
        return YES;
    }

    [[UIApplication sharedApplication] openURL:[request URL]];
    return NO;
}
Emil
  • 7,220
  • 17
  • 76
  • 135
0

I am not sure why this fixed my issue, but it did.

My View controller that called up the webview was in a static library because it was being re-used in other apps. By just moving the code out of the static library and into the application it self, the app started working much better and the web view works as well as one can expect now. There is no longer any difference between iOS 5 and iOS 6.

But by adding this code, it really made a huge difference :

NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]) {
    [storage deleteCookie:cookie];
}

Like I said, I can't explain why moving the code into the app itself instead of having it as a library and the above code works, but I am sure it has something to do with how webview caches.

Trausti Thor
  • 3,722
  • 31
  • 41