1

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?

timetofly
  • 2,957
  • 6
  • 36
  • 76
  • 1
    UIWebView is completely deprecated in iOS 12. Switch to WKWebView. – matt Apr 19 '19 at 14:56
  • @matt I see that it was deprecated recently, but that does not mean it should stop working until it's removed. – timetofly Apr 19 '19 at 15:30
  • Well the method you are calling, `openURL:`, is also deprecated, since iOS 10. What I'm saying is: you use a deprecated class to call a deprecated method; if that doesn't work, it's not a useful thing to ask about on Stack Overflow. You break the rules, you must live with the breakage. – matt Apr 19 '19 at 16:11
  • Likely duplicate of https://stackoverflow.com/questions/39548010/openurl-deprecated-in-ios-10 – matt Apr 19 '19 at 16:13

0 Answers0