通用链接无法与WKWebView一起使用 [英] Universal links not working with WKWebView

查看:484
本文介绍了通用链接无法与WKWebView一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在公司有基于 web-view 的应用和其他原生应用。我们使用通用链接在需要时将用户重定向到其他应用程序(其他应用程序仍支持通用链接 - 我可以运行通过按 Apple Notes应用程序中的链接来实现它们。
我们最近转换到 WKWebView (来自 UIWebView ),这提供了一种更好的体验方式。但更新后通用链接停止工作,当用户在我们的应用程序内按链接时,我们无法启动其他应用程序。

I have web-view based app and other native apps in company. We were using universal links to redirect user to other apps when needed (other apps still support universal links - I can run them by pressing links from Apple Notes app). We recently made a transition to WKWebView (from UIWebView), which provides a way better experience. But after the update Universal Links stopped working and we cannot start other apps when user press link inside our app.

根据文档:


通用链接让iOS 9用户在WKWebView中点击您的网站
链接时打开您的应用和UIWebView视图和Safari页面,
除了导致调用openURL的链接外,例如在邮件,消息和其他应用程序中发生的

"Universal links let iOS 9 users open your app when they tap links to your website within WKWebView and UIWebView views and Safari pages, in addition to links that result in a call to openURL:, such as those that occur in Mail, Messages, and other apps."

来源: https://developer.apple.com/library/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html

它似乎 WKWebView 没有处理 Universal Links 。我的问题是,我错过了 WKWebView 的一些特殊配置,或者这是 WebKit 错误?我正在创建提供的Web视图:

It seems that WKWebView is not handling the Universal Links. My questions is, am I missing some special configuration for WKWebView or this is WebKit bug? I'm creating web view as provided:

WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];  
config.allowsInlineMediaPlayback = YES;  
config.processPool = // Here I'm using shared process pool  

self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config];  
self.webView.translatesAutoresizingMaskIntoConstraints = NO;  
self.webView.clipsToBounds = YES;  
self.webView.allowsBackForwardNavigationGestures = YES;  

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {  
  self.webView.allowsLinkPreview = YES;  
}  
[self addSubview:_webView];

为了显示问题,我用简单的app创建了简单的存储库( https://github.com/apan06/UniversalLinks - 初始化非常简单)。有两个Web视图 - WKWebView UIWebView ,两者都有简单的html,只有<$ c $的链接C>微博。 WKWebView 只需加载 Twitter 页面。另一方面 UIWebView 打开 Twitter app。只需记住:
- 如果您没有 Twitter应用 Twitter 应用的设备上进行测试>或者不喜欢Twitter,你可以更改链接
- 我在 iPhone 6 上测试它与 iOS 9.2.1

To show the problem I have created simple repository with simple app (https://github.com/apan06/UniversalLinks - with very simple initialisation). There are two web views - WKWebView and UIWebView with both with simple html that there is only link to Twitter. WKWebView simply loads the Twitter page. On the other hand UIWebView open Twitter app. Just remembet: - test it on device with Twitter app installed, if you don't have Twitter app or don't like Twitter you can change link - I was testing it on iPhone 6 with iOS 9.2.1

谢谢!

推荐答案

我相信有WKWebView中的一个错误,如果没有设置导航委托,它会忽略通用链接。尝试设置WKWebView的导航委托。您不必实现任何委托方法。

I believe there is a bug in WKWebView that makes it ignore universal links if the navigation delegate is not set. Try setting the WKWebView’s navigation delegate. You don’t have to implement any of the delegate methods.

这篇关于通用链接无法与WKWebView一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆