Universal links not working with WKWebView(通用链接不适用于 WKWebView)
问题描述
我在公司有基于 web-view
的应用程序和其他本地应用程序.我们在需要时使用 universal links
将用户重定向到其他应用程序(其他应用程序仍然支持 universal links
- 我可以通过按 Apple Notes 应用程序代码>).我们最近过渡到
WKWebView
(来自 UIWebView
),它提供了更好的体验.但是更新后 Universal Links
停止工作,当用户在我们的应用程序中按下链接时,我们无法启动其他应用程序.
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];
为了显示问题,我使用简单的应用程序创建了简单的存储库(https://github.com/apan06/UniversalLinks - 非常简单的初始化).有两个 web 视图 - WKWebView
和 UIWebView
,两者都带有简单的 html,只有 Twitter
的链接.WKWebView
只是加载 Twitter
页面.另一方面 UIWebView
打开 Twitter
应用程序.请记住:- 在安装了 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通用链接不适用于 WKWebView
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01