最近的12.2更新使WebView中的某些功能停止工作,奇怪的是,仅在实际设备上运行-在模拟器中工作正常。在Web视图中单击链接时,一些代码确定该链接是应在Web视图中打开还是打开新的浏览器窗口。链接是带有target="_blank"
的标准href链接。确定是否打开新浏览器窗口的代码如下:
#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;
}
如您所见,所有未链接到mywebviewdomain.com
的链接都应打开一个新的浏览器窗口。在实际设备上,单击链接不会发生任何事情。在iOS 12.2模拟器中可以正常工作。
这是什么问题?网页上有什么我可以做的解决方案,以避免必须进行应用程序更新?