我什么时候可以使用带有通用链接的SFSafariViewController,WKWebView或UIWebView? [英] When can I use a SFSafariViewController, WKWebView, or UIWebView with universal links?

查看:271
本文介绍了我什么时候可以使用带有通用链接的SFSafariViewController,WKWebView或UIWebView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Universal Links 部分> iOS应用搜索编程指南,Apple说:

In the Universal Links section of the iOS App Search Programming Guide, Apple says:


如果你实例化一个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.

处理通用链接是什么意思?我是否可以使用 SFSafariViewController WKWebView UIWebView来打开给定的URL ?它是否仅适用于 - [UIApplicationDelegate应用程序:continueUserActivity:restorationHandler:] ,或者是否存在超时?这是否意味着我们无法在 SFSafariViewController WKWebView 中打开URL UIWebView

What does "handle a universal link" mean? Can I not ever open the given URL with an SFSafariViewController, WKWebView, or UIWebView? Does it only apply during -[UIApplicationDelegate application:continueUserActivity:restorationHandler:], or is there a timeout in place? Does this mean we can't ever open the URL in a SFSafariViewController, WKWebView, or UIWebView?

推荐答案

我不确定我完全理解你的问题。

I'm not sure I fully understand your question.

为了涵盖基础知识,我将允许Apple解释通用链接是什么

Just to cover basics, I'll allow Apple to explain what a Universal Link is:


通用链接允许用户在WKWebView和UIWebView视图和Safari页面中点击指向您网站的链接时打开您的应用,此外还有导致调用openURL的链接:,例如Mail中出现的链接,消息和其他应用程序。

Universal links let 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.

所以基本上,假设您正在使用Twitter客户端,并且经历时间表,您遇到包含以下YouTube视频链接的推文: https://youtu.be/ejQod8liXm0

So basically, imagine you're working on a Twitter client, and going through the timeline, you encounter a tweet with the following YouTube video link: https://youtu.be/ejQod8liXm0

如果你点击它,因为它是一个HTTP URL,你希望Safari打开链接。但是,我认为我们所有iOS开发人员几乎都同意本机应用程序更好的事实,因此更好的用户体验将是官方YouTube应用程序打开视频,甚至来自您的第三方客户。

If you tap it, since it's an HTTP URL, you'd expect Safari to open the link. However, I think we all iOS developers can pretty much all agree on the fact that native apps are better, so a better user experience would be for the official YouTube app to open the video, even from your third-party client.

这就是环球链接所允许的;如果YouTube应用在iOS上注册为负责处理 https://www.youtube.com 的应用( *)链接,如果我们遵循API规则,iOS生态系统中的每个人都会受益。如果您运行一个网站并且您希望任何内容触发您的官方iOS应用程序在您的用户安装它时打开,或者如果用户想要为更好的用户安装它,则会发生同样的事情经验(当然也有助于你的业务)。

This is what "Universal Links" allow; if the YouTube app registers itself on iOS as the app responsible for handling https://www.youtube.com(*) links, everyone in the iOS ecosystem benefits if we follow the API rules. The same thing happens if you run a website and you want any of your content to trigger your official iOS app to open if your user has it installed, or for the user to be prompted if they'd like to install it for a better user experience (and to help your business, of course).

所以,尽管如此,让我们回到原始文本:

So, with all of this out of the way, let's get back to the original text:


如果您实例化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.

什么这意味着,如果来自您的应用,您的用户会点击您内容的通用链接(例如: http ://www.your-company.com/foo ),并且您没有通过正则表达式在应用程序的代码中检测到这一点,而是实例化 SFSafariViewController WKWebView UIWebView 打开它,好像它是纽约时报或其他什么,操作系统会明白,不是在你的应用程序中打开它,你想要Safari为你处理这个请记住:Universal Links的全部目的是让用户通过本机应用程序处理URL而不是浏览器来获得更好的体验。

What this means is that, if from your app, your user taps on a Universal Link to your content (example: http://www.your-company.com/foo), and you do not detect this in your app's code via a regular expression for example, and instead instantiate a SFSafariViewController, WKWebView or UIWebView to open it as if it were a regular link to The New York Times or something, the OS will understand that instead of opening this in your app, you want Safari to handle this for you. Remember: the whole purpose of Universal Links is for the user to get a better experience by having the URL being handled by a native app, not by the browser.

这是第一句话。至于第二个,它清除了一个潜在的后续问题:如果用户从嵌入式浏览器从另一个不属于我的应用程序中点击我的内容的Universal Link怎么办?然后,句子说,操作系统将正常运行:它将打开您的应用程序,遵守通用链接规则。

This is what the first sentence says. As for the second, it clears up a potential follow-up question: what if the user taps on a Universal Link to my content from an embedded browser from another app that's not mine? Then, the sentence says, the OS will behave normally: it will open your app, respecting Universal Link rules.

TL; DR:您需要检测来自您的内容的通用链接你的应用程序也是代码,并处理它们。 iOS不会为您处理此问题。相反,如果您告诉操作系统从您的应用程序在嵌入式浏览器中打开应用程序内容的通用链接,它将完全按照说明执行。

TL;DR: You need to detect Universal Links to your content from your app too, in code, and handle them. iOS will not handle this for you. Instead, if you tell the OS to open a Universal Link to your app's content in an embedded browser from your app, it will do exactly as told.

编辑:如果您需要帮助决定询问 SFSafariViewController -openURL:options:completitionHandler: API to打开一个网址,此链接可以帮助您; 我的建议是首先使用 -openURL:options:completitionHandler:,如果不成功,则使用 SFSafariViewController 或类似

If you need help deciding between asking SFSafariViewController or the -openURL:options:completitionHandler: APIs to open a URL, this link should help you; my recommendation would be to use -openURL:options:completitionHandler: first, and if it's not successful, then use SFSafariViewController or similar.

希望这会有所帮助,并且我已正确理解您的问题。

Hope this helps and that I've correctly understood your question.

干杯!和快乐的iOS 11编程! :)

Cheers! And Happy iOS 11 programming! :)

这篇关于我什么时候可以使用带有通用链接的SFSafariViewController,WKWebView或UIWebView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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