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

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

NSURL*URL =[NSURLURLWithString:@"https://itunes.apple.com/cn/app/id1013277346?mt=8"];

NSURLRequest*request = [NSURLRequestrequestWithURL:URL];

self.webView = [UIWebViewnew];

self.webView.delegate =self;

[self.webView loadRequest:request];

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

- (void)loadWithWKWebView{

NSURL*URL = [NSURLURLWithString:@"https://itunes.apple.com/cn/app/id1013277346?mt=8"];

NSURLRequest*request = [NSURLRequestrequestWithURL:URL];

self.wkWebView = [WKWebViewnew];

self.wkWebView.navigationDelegate =self;

[self.wkWebView loadRequest:request];

}

- (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction decisionHandler:(void(^)(WKNavigationActionPolicy))decisionHandler{

   WKNavigationActionPolicypolicy =WKNavigationActionPolicyAllow;

    /* 简单判断host,真实App代码中,需要更精确判断itunes链接 */

     if([[navigationAction.request.URL host] isEqualToString:@"itunes.apple.com"] &&

   [[UIApplicationsharedApplication] openURL:navigationAction.request.URL]){

    policy =WKNavigationActionPolicyCancel;}

   decisionHandler(policy);

}

难以理解为啥WKWebView上不支持跳转至AppStore。

如果不处理,普通网页上链接至itunes的,点击后都无法跳转了。


WKWebView里面的链接要特殊处理,90一下的系统加载本地文件也是有问题的,我有空写篇博客落,还是蛮多坑的

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容