使用WKWebView打开itunes链接无法跳转至AppStore

UIWebView上,不需要特殊处理直接加载 itunes 链接是可以直接跳转至AppStore的。

NSURL *URL = [NSURL URLWithString:@"https://itunes.apple.com/cn/app/id1013277346?mt=8"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
self.webView = [UIWebView new];
self.webView.delegate = self;
[self.webView loadRequest:request];

但是,在WKWebView上则不行,需要在navigationDelegate中拦截,手动openURL才能跳转至AppStore。

- (void)loadWithWKWebView
{
NSURL *URL = [NSURL URLWithString:@"https://itunes.apple.com/cn/app/id1013277346?mt=8"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
self.wkWebView = [WKWebView new];
self.wkWebView.navigationDelegate = self;
[self.wkWebView loadRequest:request];
}
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
WKNavigationActionPolicy policy = WKNavigationActionPolicyAllow;
/* 简单判断host,真实App代码中,需要更精确判断itunes链接 */
if ([[navigationAction.request.URL host] isEqualToString:@"itunes.apple.com"] &&
[[UIApplication sharedApplication] openURL:navigationAction.request.URL])
{
policy = WKNavigationActionPolicyCancel;
}
decisionHandler(policy);
}

难以理解为啥WKWebView上不支持跳转至AppStore。
如果不处理,普通网页上链接至itunes的,点击后都无法跳转了。

您的支持将鼓励我继续创作。