Prevent universal links from opening in `WKWebView`/`UIWebView`(防止通用链接在 `WKWebView`/`UIWebView` 中打开)
问题描述
当用户点击 WKWebView
中的通用链接时,将打开相应的应用程序(如果已安装).
When user tap on a universal link in WKWebView
, the corresponding app will be opened (if installed).
这在 Apple 搜索编程指南一个>
如果您实例化 SFSafariViewController、WKWebView 或 UIWebView 对象来处理通用链接,iOS 会在 Safari 中打开您的网站,而不是打开您的应用程序.但是,如果用户从嵌入式 SFSafariViewController、WKWebView 或 UIWebView 对象中点击通用链接,iOS 会打开您的应用.
If you instantiate a SFSafariViewController, WKWebView, or UIWebView object to handle a universal link, iOS opens your website in Safari instead of opening your app. However, if the user taps a universal link from within an embedded SFSafariViewController, WKWebView, or UIWebView object, iOS opens your app.
在我的应用中,我有一个 WKWebView
,但我不希望用户离开我的应用.我想处理我的 WKWebView
中的链接.
In my app, I have a WKWebView
, but I don't want the user to go out of my app. I want to handle the link within my WKWebView
.
如何防止通用链接打开?或者我可以知道一个 URL 是否可以被其他应用处理?
How do I prevent universal link from opening? Or can I know if a URL could be handle by other apps?
推荐答案
WebKit 源代码:
sourcecode for WebKit:
static const WKNavigationActionPolicy WK_API_AVAILABLE(macosx(10.11), ios(9.0)) _WKNavigationActionPolicyAllowWithoutTryingAppLink = (WKNavigationActionPolicy)(WKNavigationActionPolicyAllow + 2);
如果您使用 WKWebView
,只需使用 WKNavigationActionPolicyAllow
+ 2 而不是 WKNavigationActionPolicyAllow
if you are using WKWebView
, just use WKNavigationActionPolicyAllow
+ 2 instead of WKNavigationActionPolicyAllow
这篇关于防止通用链接在 `WKWebView`/`UIWebView` 中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:防止通用链接在 `WKWebView`/`UIWebView` 中打开


基础教程推荐
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 固定小数的Android Money Input 2022-01-01