iOS 12.2 update stopped WebView from opening links in new browser window

863 Views Asked by At

The recent 12.2 update stopped some functionality in our WebView from working, strangely only on real devices--it works fine in simulators. When a link is clicked in the webview, some code determines whether the link should open in the webview, or open up a new browser window. The links are standard href links with target="_blank". The code to determine whether or not to open a new browser window looks like this:

#pragma UIWebView delegate
- (BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest   navigationType:(UIWebViewNavigationType)inType
{
    BOOL shouldOpenBrowser = NO;
    if ((inRequest.URL.absoluteString.length > 0) && (![inRequest.URL.absoluteString isEqualToString:@"about:blank"])) {

        self.strUrl = [NSString stringWithFormat:@"%@", [inRequest URL]];

        if ([inRequest.URL.absoluteString containsString:@"google.com/recaptcha"]) {
            shouldOpenBrowser = NO;
        } else if (![inRequest.URL.host hasSuffix:@"mywebviewdomain.com"]) {
            shouldOpenBrowser = YES;
        } else {
            NSString *strMatchedUrl = [NSString stringWithFormat:@"https://mywebviewdomain.com/link/%@/%@/%@",self.var1, self.var2,self.var3];
            if (![inRequest.URL.absoluteString containsString:strMatchedUrl]) {
                shouldOpenBrowser = NO;
            } else {
                shouldOpenBrowser = YES;
            }
        }
    }else if([inRequest.URL.absoluteString hasPrefix:@"newtab:"])
             {

                 NSURL *url = [NSURL URLWithString:[inRequest.URL.absoluteString substringFromIndex:7]];
                 [[UIApplication sharedApplication] openURL:url];

                 return true;
             }

    if (shouldOpenBrowser == YES) {
         [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }

    return YES;
}

As you can see, all links that don't go to mywebviewdomain.com should open a new browser window. On real devices, nothing happens when the links are clicked. It works fine in iOS 12.2 simulators.

What's the problem here? And is there any solution I can do in the webpage, to avoid having to do an app update?

0

There are 0 best solutions below