简体   繁体   中英

iOS 8.4.1 broke UIWebView?

I inherited a project that uses a UIWebView that is not displayed to the user to load HTML with a reference to a JS file for calculations and has been working for quite some time without issue.

I have verified that the JS file and the HTML and the code has not changed.

As of the release of iOS 8.4.1 Aug 13, problems with this section of code started appearing to customers.

- (void)loadCompleteHTML:(NSString*)completeHTML {
    self.caculateWebView = [[UIWebView alloc] init];
    self.caculateWebView.delegate = self;
    [self.caculateWebView loadHTMLString:completeHTML baseURL:nil];
}

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

    if ([[request.URL.scheme lowercaseString] isEqualToString:@"success"]) {
        //do something with the success
        .
        .
        return NO;

    } else if ([[request.URL.scheme lowercaseString] isEqualToString:@"fail"]) {
        //do something with the fail
        .
        .
        return NO;
    }

    return YES;

}

It is not returning a "success" nor a "fail" yet, the only two conclusions possible from this HTML/JS is either of those two.

By logging the request.URL.absoluteString , I saw iOS 8.4.1 UIWebView suddenly calling about:blank as the first URL upon load. My solution was to ask the UIWebView to reload only the first time.

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

    BOOL calledForReload = NO;

    if ([[request.URL.scheme lowercaseString] isEqualToString:@"success"]) {
        //do something with the success
        .
        .
        return NO;

    } else if ([[request.URL.scheme lowercaseString] isEqualToString:@"fail"]) {
        //do something with the fail
        .
        .
        return NO;
    } else if (!calledForReload) {
        //call for reload
        calledForReload = YES;
        [webView reload];
    }

    return YES;

}

Hopefully my solution to this issue will help someone equally as dumfounded as I was.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM