iOS 上的通用链接与深层链接(URL 方案)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35522618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Universal links on iOS vs. deep links (URL schemes)
提问by AppsDev
As I'm reading, iOS 9 introduced Universal Links. In the "Support Universal Links" section in Apple's App Search Programming Guide, it says that this is not exactly like deep linking with URL schemes, but I'm not totally clear about this topic:
在我阅读时,iOS 9 引入了通用链接。在 Apple's App Search Programming Guide的“支持通用链接”部分,它说这与使用 URL 方案进行深度链接并不完全一样,但我对这个主题并不完全清楚:
- What is actually the difference(s) between Universal Link and the URL Schemes? Is it that a Universal Link is only for hyperlinks in websites, and the Mail or Messages apps?
- Do Universal Links replace URL schemes?
- Are Universal Links a type of deep link?
- 通用链接和 URL 方案之间的实际区别是什么?通用链接是否仅适用于网站、邮件或消息应用程序中的超链接?
- 通用链接会取代 URL 方案吗?
- 通用链接是一种深层链接吗?
回答by ahay
TL,DR:
TL,博士:
What is actually the difference(s) between Universal Link and the URL Schemes? Is it that a Universal Link is only for hyperlinks in websites, and the Mail or Messages apps?
通用链接和 URL 方案之间的实际区别是什么?通用链接是否仅适用于网站、邮件或消息应用程序中的超链接?
A Universal Link is an Apple Specific, OS-based URL that ties a website URL to an app-specific URI Scheme & Route. It is not available in all apps - as the app has to support the behavior. There is a good list of where/how UL's currently work (here).
通用链接是 Apple 特定的、基于操作系统的 URL,它将网站 URL 与应用程序特定的 URI 方案和路由相关联。它并非在所有应用程序中都可用 - 因为该应用程序必须支持该行为。有一个很好的 UL 当前工作地点/方式列表(这里)。
There are tons of problems with UL's as well which I outline at the very end. See long read below.
UL 也有很多问题,我在最后概述了这些问题。请参阅下面的长文。
Do Universal Links replace URL schemes?
通用链接会取代 URL 方案吗?
No. They are a forced replacement for URI Schemes and routes on iOS Safari. You must and should still support your app's URI scheme and routes since Android and iOS Chrome still use this technology, as do every major class of link vendors from attribution through email.
不。它们是 iOS Safari 上 URI Schemes 和路由的强制替代品。你必须而且应该仍然支持你的应用程序的 URI 方案和路由,因为 Android 和 iOS Chrome 仍然使用这项技术,从归因到电子邮件的每一类主要链接供应商也是如此。
Are Universal Links a type of deep link?
通用链接是一种深层链接吗?
Yes and no. Universal Links in themselves are not universal deeplinks - they can't route through the install process for example. But when the user has the app, they can deeplink. Better to think about all links in terms of what they can and can't do, rather than classify URLs into "deeplinks" and "not deeplinks."
是和否。通用链接本身并不是通用的深层链接——例如,它们不能通过安装过程进行路由。但是当用户拥有该应用程序时,他们可以进行深度链接。最好根据它们能做什么和不能做什么来考虑所有链接,而不是将 URL 分为“深层链接”和“非深层链接”。
Many links exhibit the behavior to deeplink depending on whether the user has the app and the context (browser, application, OS, OS version etc.) Change the frame of thinking.
许多链接表现出深度链接的行为取决于用户是否拥有应用程序和上下文(浏览器、应用程序、操作系统、操作系统版本等)。改变思维框架。
Tracking Universal Links
跟踪通用链接
Throughout the below document I outline all the different aspects of Universal Links. It's important to call out that continueUserActivity
will report the referring URL from a Universal Link, so you can use this to attribute opens.
在下面的文档中,我概述了通用链接的所有不同方面。重要的是要调用它continueUserActivity
会报告来自通用链接的引用 URL,因此您可以使用它来属性打开。
Because a UL is not a normal link, if you have redirects, that will break it. Similarly, if you turn off redirects, then whatever website click server you have will never get hit. This is for a different discussion, but important to note.
因为 UL 不是普通链接,如果您有重定向,那将破坏它。同样,如果您关闭重定向,那么您拥有的任何网站点击服务器都不会受到攻击。这是一个不同的讨论,但重要的是要注意。
Lots of helpful information I've curated below on Universal Links if you're interested.
如果您有兴趣,我在下面的 Universal Links 上精选了许多有用的信息。
URI Schemes
URI 方案
Most people are familiar with URI schemes. A URI is a Universal Resource Indicator (link). URIs can be allocated to mobile applications. Typing in a URI, like airbnb:// will attempt to locate the app resource Airbnb on the device.
大多数人都熟悉 URI 方案。URI 是统一资源指示符(链接)。URI 可以分配给移动应用程序。输入 URI,例如 airbnb:// 将尝试在设备上定位应用程序资源 Airbnb。
Before Universal Links or App Links existed (that is, before iOS 9.3/Android 6.0), one would need to use a “custom URI scheme” and the route in the form of airbnb://d/listing/530250
to deep link a user to specific content in a mobile app (in this case a listing). However, this was not secure nor did it handle the case when a user did not have the app installed (there was no fallback). The way that most attribution partners (Appsflyer, Kochava, Button, Yozio, Branch etc.) would work is that they would provide a link that handled this.
在 Universal Links 或 App Links 存在之前(即在 iOS 9.3/Android 6.0 之前),人们需要使用“自定义 URI 方案”和路由形式airbnb://d/listing/530250
将用户深度链接到移动应用程序中的特定内容(在这种情况下是一个列表)。但是,这并不安全,也无法处理用户未安装应用程序的情况(没有后备)。大多数归因合作伙伴(Appsflyer、Kochava、Button、Yozio、Branch 等)的工作方式是提供一个链接来处理此问题。
When the user visits the page of this URL, there would be some javascript that would set a timer and then try to launch the URI Scheme from the browser with some simple javascript:
当用户访问这个 URL 的页面时,会有一些 javascript 会设置一个计时器,然后尝试使用一些简单的 javascript 从浏览器启动 URI Scheme:
window.location.href(...)
If the app didn't open before the timer expired, then the vendor could assume the phone did not contain the app, and so instead, some javascript would fire to open the iTunes or Android URL instead. This mechanism relied on blocking javascript in the browser.
如果应用程序在计时器到期之前没有打开,那么供应商可以假设手机不包含该应用程序,因此,一些 javascript 会触发以打开 iTunes 或 Android URL。这种机制依赖于在浏览器中阻止 javascript。
In iOS 9.3, Apple removed blocking javascript in Safari (link). The end result is that whenever you tried to open an app with a URI scheme in Safari, you would see a big error message that said, “Cannot Open Page.” This was a terrible user experience and led to the enforcement of Apple's new system, Apple Universal Links.
在 iOS 9.3 中,Apple 移除了 Safari 中的阻止 javascript(链接)。最终结果是,每当您尝试在 Safari 中打开具有 URI 方案的应用程序时,您都会看到一条大错误消息,内容为“无法打开页面”。这是一种糟糕的用户体验,并导致强制执行 Apple 的新系统 Apple Universal Links。
Apple Universal Links & Android App Links are essentially web URLs (e.g., https://www.airbnb.com/rooms/530250
) which are intended to direct users to the optimal location on web or the app. They were intended to take users to mobile web if the user doesn't have the app, but take the user to the exact content in the app if they do. On a mobile device, if the user follows a universal link and has our app installed, they may be directed to the app, otherwise the system will fallback and land the visitor on our mobile website (with a few exceptions -- see below).
Apple 通用链接和 Android 应用程序链接本质上是 Web URL(例如https://www.airbnb.com/rooms/530250
),旨在将用户引导到 Web 或应用程序上的最佳位置。如果用户没有该应用程序,它们旨在将用户带到移动网络,但如果用户拥有该应用程序,则将用户带到应用程序中的确切内容。在移动设备上,如果用户点击通用链接并安装了我们的应用程序,他们可能会被定向到该应用程序,否则系统将回退并将访问者登陆我们的移动网站(少数例外 - 见下文)。
For a link to be truly Universal, it requires that the linked feature is enabled on web, iOS and Android and for all apps to share the same resource path.
要使链接真正通用,需要在 Web、iOS 和 Android 上启用链接功能,并且所有应用程序共享相同的资源路径。
Apple Universal Links & Android App Links
苹果通用链接和安卓应用链接
Apple Universal Links (iOS) and Android App Links (Android) are essentially the same concept, but are often interchanged, or confused with other routing mechanisms. It's important to be explicit when you talk about these concepts, else you risk confusing or confounding different technologies which operate very differently.
Apple Universal Links (iOS) 和 Android App Links (Android) 本质上是相同的概念,但经常互换,或与其他路由机制混淆。当你谈论这些概念时,明确是很重要的,否则你可能会混淆或混淆运行非常不同的不同技术。
Specifically, Apple Universal Links are a standard from Apple that is deployed on the iPhone operating system (OS), which allows a user to tap a link and be delivered immediately to the app if they have it. Apple Universal Links do not have redirects. It is a special system setup with some degree of technical complexity. When the user taps the link, a roundtrip server call is made to Apple and the OS opens the app immediately without ever opening the browser or loading the URL. More about how this works below.
具体来说,Apple Universal Links 是 Apple 的一项标准,它部署在 iPhone 操作系统 (OS) 上,它允许用户点击链接并在拥有链接时立即将其传送到应用程序。Apple 通用链接没有重定向。这是一种特殊的系统设置,具有一定程度的技术复杂性。当用户点击链接时,会向 Apple 进行往返服务器调用,操作系统会立即打开应用程序,而无需打开浏览器或加载 URL。更多关于它的工作原理如下。
Android App Links is the equivalent linking system that is setup on Android.
Android App Links 是在 Android 上设置的等效链接系统。
Universal Links start by hosting an “Apple App Site Association File” (AASA) for each of your domains.
通用链接首先为您的每个域托管一个“Apple 应用程序站点关联文件”(AASA)。
It's important to note that almost every company's AASA is hosted at their main domain followed by “/apple-app-site-association”
需要注意的是,几乎每家公司的 AASA 都托管在其主域中,后跟“/apple-app-site-association”
Some examples:
一些例子:
https://www.jet.com/apple-app-site-associationhttps://www.pinterest.com/apple-app-site-association
https://www.jet.com/apple-app-site-association https://www.pinterest.com/apple-app-site-association
If you click these URLs, it will download the company's AASA. An AASA example is on the right hand side. Some notable things included in an AASA: AppID for all the apps where Universal Links can be applied. In ours and many other AASA's you will see setup for the production and test versions of the app so that links will work across all versions for testing. The AppID is structured as the App Prefix, followed by the Bundle ID. Usually each test version of the app has a different prefix, but the Bundle ID stays consistent.
如果您单击这些 URL,它将下载该公司的 AASA。AASA 示例位于右侧。AASA 中包含的一些值得注意的内容:适用于可以应用通用链接的所有应用程序的 AppID。在我们和许多其他 AASA 中,您将看到该应用程序的生产和测试版本的设置,以便链接将适用于所有版本的测试。AppID 的结构为 App Prefix,后跟 Bundle ID。通常应用程序的每个测试版本都有不同的前缀,但 Bundle ID 保持一致。
Example... {App Prefix}.{ Bundle ID }
示例... {App Prefix}.{ Bundle ID }
Paths: These are the pathways that will open up the app immediately if the user has it. The app will receive the referring URL and can parse out the proper pathway to deeplink the user to content there-after.
路径:如果用户拥有它,这些路径将立即打开应用程序。该应用程序将收到引用 URL,并可以解析出正确的路径,将用户深层链接到之后的内容。
Most attribution vendors, like Branch or Appsflyer, also can host an AASA for you in certain cases (example: Branch's AASA for Airbnb is hosted on the custom domain https://abnb.me/apple-app-site-association).
大多数归因供应商,如 Branch 或 Appsflyer,在某些情况下也可以为您托管 AASA(例如:Branch 的 AASA for Airbnb 托管在自定义域https://abnb.me/apple-app-site-association 上)。
These files effectively whitelist and blacklist the URLs to map, or not map, to in the app. Just like with a company-owned AASA, for each domain, the vendor specifies the App IDs and the URL paths such as:
这些文件有效地将要映射或不映射到应用程序中的 URL 列入白名单和黑名单。就像公司拥有的 AASA 一样,对于每个域,供应商指定应用 ID 和 URL 路径,例如:
5LL7P8E8RA.com.airbnb.app
"/rooms/*"
"/wishlists/*"
"/invite"
"NOT /rooms/*/building-rules"
When users install or upgrade our app, iOS fetches the AASA files for all domains listed in our app's entitlements to make sure that our websites allow our app to open URLs on their behalf.
当用户安装或升级我们的应用程序时,iOS 会获取我们应用程序权限中列出的所有域的 AASA 文件,以确保我们的网站允许我们的应用程序代表他们打开 URL。
Known Problems with Universal Links
通用链接的已知问题
Universal Links work great in most cases, however these can easily and, inadvertently, be disabled! If this happens the user will always be redirected to the website URL until they upgrade their app or reset what we call their “Entitlements File” (link).
通用链接在大多数情况下都很好用,但是这些很容易并且无意中被禁用!如果发生这种情况,用户将始终被重定向到网站 URL,直到他们升级他们的应用程序或重置我们所谓的“权利文件”(链接)。
If a user taps on the ‘airbnb.com' or ‘abnb.me' link in the top-right of our app, the OS will direct the user to the website, but it will also permanently direct any future Universal Link to the mobile website for links with that domain!
如果用户点击我们应用程序右上角的“airbnb.com”或“abnb.me”链接,操作系统会将用户定向到该网站,但它也会将任何未来的通用链接永久定向到移动设备与该域的链接的网站!
This effectively breaks the functionality of Apple Universal Links for the user. This isn't trackable right now and the only way to reset is to long press the URL and click “Open in “Airbnb”” (not intuitive) or to tap the “Open” button on the Apple Universal Links Banner (Phantom Banner) that was described earlier in this document.
这有效地破坏了用户的 Apple 通用链接的功能。这现在无法跟踪,唯一的重置方法是长按 URL 并单击“在“Airbnb”中打开(不直观)或点击 Apple Universal Links Banner(Phantom Banner)上的“打开”按钮这在本文档前面已经描述过。
Apple Universal Links Banner
Apple 通用链接横幅
These AASA paths are also used to determine when to display, or not display, the iOS system's “Universal Links Banner.”
这些 AASA 路径还用于确定何时显示或不显示 iOS 系统的“通用链接横幅”。
This is a particularly hot topic that arises in conversations often and is worth discussing.
这是一个特别热门的话题,经常出现在谈话中,值得讨论。
When you enable Apple Universal Links on a particular domain, Apple will inject a system App Banner on the Safari Browser. This means that in addition to whatever banners or web interstitials we display, Apple will also force a non-customizable, non-trackable Universal Links banner, that displays at the top of Safari for users who have the app and are viewing a URL in Safari who's path is in the AASA.
当您在特定域上启用 Apple 通用链接时,Apple 将在 Safari 浏览器上注入系统应用横幅。这意味着除了我们显示的任何横幅或网页插页式广告外,Apple 还将强制使用不可自定义、不可跟踪的通用链接横幅,该横幅显示在 Safari 顶部,供拥有该应用程序并在 Safari 中查看 URL 的用户使用谁的路径在 AASA 中。
We have no control over how this banner looks. We can only determine if it should be visible on a page based on the AASA. We also currently have no way to identify if or when a user taps the ‘OPEN' button (IE no attribution.
我们无法控制此横幅的外观。我们只能根据 AASA 确定它是否应该在页面上可见。我们目前也无法确定用户是否或何时点击“打开”按钮(即无归属。
Summary of Apple Universal Links Banner Attributes:
Apple Universal Links Banner 属性总结:
- ONLY displayed if the user has the app.
- NOT the same as the Apple Smart App Banner
- ONLY displayed on iOS Safari Browser.
- Not customizable, except, you can customize the text of the title and description in this banner with the The iTunesMetadata.plist Contents (link).
- No attribution or tracking.
- 仅当用户拥有该应用程序时才显示。
- 与 Apple Smart App Banner 不同
- 仅显示在 iOS Safari 浏览器上。
- 不可自定义,除了您可以使用 iTunesMetadata.plist 内容(链接)自定义此横幅中的标题和描述文本。
- 没有归属或跟踪。
回答by micmdk
Universal links is the iOS's capability of sending web url request to a given app, instead of opening them in the browser.
通用链接是 iOS 将 Web url 请求发送到给定应用程序的功能,而不是在浏览器中打开它们。
URL-schemes is an apps ability to open in a given state, described by the url, and handled in code by the developer.
URL-schemes 是一种应用程序在给定状态下打开的能力,由 url 描述,并由开发人员在代码中处理。
Say you have an app called "Cool App", and you've registed the url-scheme
"coolapp". And your app have different areas like "Nice gadgets" and "Nice stuff".
Now you can open your app with at link link coolapp://nice-gadgets
. To make the app open on the nice gadget section, you have to implement the application(_:openURL:options:)
method, and within this discover the requested url, and make the app open the requested view controller.
假设您有一个名为“Cool App”的应用程序,并且您已经注册了 url-scheme“coolapp”。而且您的应用程序有不同的区域,例如“不错的小工具”和“不错的东西”。现在您可以使用 at link link 打开您的应用程序coolapp://nice-gadgets
。要在 nice gadget 部分打开应用程序,您必须实现该application(_:openURL:options:)
方法,并在其中发现请求的 url,并使应用程序打开请求的视图控制器。
At the same time you have a website called www.coolapp.com
. When browsing using an iOS device, and you come across a link to your site - say www.coolapp.com/nice-gadgets
, and opening the link, it will open in the browser.
By enabling universal links it will open the app instead by calling the application(_:continueUserActivity:restorationHandler:)
method given the url as parameter.
From here you can use the same logic from the url scheme handling, to open the app in the requested state.
同时,您有一个名为www.coolapp.com
. 使用 iOS 设备浏览时,您遇到指向您网站的链接 - 例如www.coolapp.com/nice-gadgets
,打开该链接后,它将在浏览器中打开。通过启用通用链接,它将通过调用application(_:continueUserActivity:restorationHandler:)
给定 url 作为参数的方法来打开应用程序。从这里您可以使用与 url 方案处理相同的逻辑,以在请求的状态下打开应用程序。
So will universal links replace url schemes? I doubt it, but they are going to compliments each other in a nice way.
那么通用链接会取代 url 方案吗?我对此表示怀疑,但他们会以一种很好的方式互相赞美。
Are universal links deep links? No, but they can initiate the process of using deep links within an app.
通用链接是深层链接吗?不,但他们可以启动在应用程序中使用深层链接的过程。
回答by Vineet Choudhary
Universal Links replace URL/URI schemes?
通用链接取代 URL/URI 方案?
In Apple's Ideal World, YES!
在苹果的理想世界中,是的!
Universal Links is a type of deep links?
通用链接是一种深层链接吗?
Because Apple force to developer user Universal Links in order to deep link. So, Universal Links is a type of deep linking by Apple. But if you see Facebook lasted SDK they implemented own WebView in order support deep linking in iOS 9.0 +. So, for Apple Universal Links better than deep linking.
因为 Apple 强制开发者用户使用 Universal Links 以进行深度链接。因此,Universal Links 是 Apple 的一种深度链接。但是如果你看到 Facebook 使用了 SDK,他们实现了自己的 WebView 以支持 iOS 9.0 + 中的深度链接。因此,对于 Apple Universal Links 来说,比深度链接更好。
回答by Arpit Dongre
This is a sample Universal Link: “http://sample-universal-link.demoapp.com”
这是一个示例通用链接:“ http://sample-universal-link.demoapp.com”
It is unique, and on being tapped it will either open the App without going through Safari(if the App is installed)or will open the website on Safari( if the App is not installed)
它是独一无二的,在被点击时,它将 在不通过 Safari 的情况下打开应用程序(如果安装了该应用程序)或将在 Safari 上打开网站(如果未安装该应用程序)
This is a sample URL Scheme: “demoapp” (demoapp://params)
这是一个示例 URL Scheme:“demoapp”(demoapp://params)
This may not be unique, and on being tapped it will open the App if it is installed. If the App is not installed, it will do nothing. One or more App may have same URL Scheme.
这可能不是唯一的,如果已安装,点击它会打开应用程序。如果未安装该应用程序,它将什么也不做。一个或多个应用程序可能具有相同的 URL Scheme。
Implementation (requirements) for Universal Link & URL Scheme are quite different, so I highly doubt that Universal links replaces URL Scheme.
通用链接和 URL 方案的实现(要求)有很大不同,所以我非常怀疑通用链接取代了 URL 方案。
Universal Link is one of the way to implement deep linking.
Universal Link 是实现深度链接的方式之一。