未发布的ios应用程序链接_我们如何使用通用链接在我们的iOS应用程序中提供无缝的登录体验...

未发布的ios应用程序链接

Universal Links enable your users to intelligently follow links to content inside your app or to your website.

通用链接使您的用户能够智能地跟随指向应用程序内或网站内容的链接。

I recently had the fantastic opportunity to attend a WWDC Lab to ask some questions about Universal Links and find out how to alleviate some of the issues we were facing. The solutions are detailed throughout this post.

最近,我有一个绝佳的机会参加WWDC实验室,以询问有关Universal Links的问题,并了解如何缓解我们面临的一些问题。 在整个这篇文章中详细介绍了解决方案。

什么是通用链接? (What are Universal Links?)

Universal Links have been available since iOS9 and provide a mechanism for your users to open content in your iOS application when tapping on web links. This is fantastic for driving traffic into your iOS application and providing a great native experience for your supported content types, such as news articles and shop listings.

自iOS9以来,通用链接就已可用,它为您的用户提供了一种在点击Web链接时在iOS应用程序中打开内容的机制。 这对于将流量吸引到您的iOS应用程序中并为受支持的内容类型(如新闻文章和商店列表)提供出色的本地体验而言,是一个绝佳的选择。

At Reach we have offered this functionality on our article pages for years, meaning that when a user taps an article link inside of Safari, their email app or other supported apps, we attempt to open the article inside the appropriate iOS application.

在Reach,我们多年来一直在文章页面上提供此功能,这意味着当用户在Safari,其电子邮件应用程序或其他受支持的应用程序中点击文章链接时,我们尝试在适当的iOS应用程序中打开文章。

Another aspect of Universal Links is they enable us to provide more seamless experiences for flows within the application, such as email verification.

通用链接的另一个方面是,它们使我们能够为应用程序中的流程提供更无缝的体验,例如电子邮件验证。

We have recently implemented an email verification flow for users that register accounts using email address and password. The user receives an email with a link they must tap to verify their account.

我们最近为使用电子邮件地址和密码注册帐户的用户实施了电子邮件验证流程。 用户收到一封电子邮件,其中包含他们必须点击以验证其帐户的链接。

We could handle this by sending an app link utilising the app scheme such as com.example.app://verify-email. However, this will not work for a subset of users who tap this link on a different device.

我们可以通过使用诸如com.example.app://verify-email之类的应用程序方案发送应用程序链接来处理此问题。 但是,这对于在其他设备上点击此链接的部分用户无效。

Instead, we opted for Universal Links, such as https://www.example.co.uk/verify-email, because this enables us to provide a fallback for those users. They will be directed to the website and allowed to complete their registration there, logging into the application manually once their verification is complete.

相反,我们选择了通用链接,例如https://www.example.co.uk/verify-email ,因为这使我们能够为那些用户提供备用。 他们将被定向到该网站并被允许在该网站上完成注册,一旦完成验证,便手动登录该应用程序。

The majority of our users get a seamless experience where they tap the link in their email and are directed into our application, their email address is verified by the supplied tokens, and they are logged in automatically.

我们的大多数用户都能获得无缝体验,他们可以点击电子邮件中的链接并直接进入我们的应用程序,其电子邮件地址已通过提供的令牌进行了验证,并且会自动登录。

Image for post
Universal Links triggering In-App Email Verification
通用链接触发应用内电子邮件验证

Below I will outline the simple steps required to set up Universal Links, and some of the gotchas that you may run across.

下面,我将概述设置通用链接所需的简单步骤,以及您可能会遇到的一些陷阱。

设置通用链接 (Setting up Universal Links)

Setting up for Universal Links is straightforward and takes three steps.

设置通用链接非常简单,只需三个步骤。

  1. Add the Associated Domains Entitlement to your application

    将关联的域权利添加到您的应用程序
  2. Host an Apple App Site Association (AASA) file on your website

    在您的网站上托管Apple App Site Association(AASA)文件
  3. Set up your App Delegate to handle activity

    设置您的应用程序代理以处理活动

将关联的域权利添加到您的应用程序 (Add the Associated Domains Entitlement to your application)

Open Xcode and navigate to the Signing & Capabilities tab of your project. Once there, tap Add Capability and select the Associated Domains option. This will add a section to this window, allowing you to add your domains.

打开Xcode并导航到项目的“签名和功能”选项卡。 到达后,点击添加功能,然后选择关联域选项。 这将在此窗口中添加一个部分,使您可以添加域。

Apple suggests providing both your www and root domains e.g. www.mirror.co.uk and mirror.co.uk.

苹果建议同时提供您的www和根域,例如www.mirror.co.ukmirror.co.uk

Associated Domains Entry
The Associated Domains entry in the Xcode Signing & Capabilities window
Xcode签名和功能窗口中的关联域条目

在您的网站上托管Apple App Site Association文件 (Host an Apple App Site Association file on your website)

The Apple App Site Association file is used to instruct your device which web links on your domain it should attempt to open inside your application.

Apple App Site Association文件用于指示您的设备应尝试在您的应用程序中打开您域中的哪些Web链接。

As of iOS14, you must host this file at:

从iOS14开始,您必须在以下位置托管此文件:

{domain}/.well-known/apple-app-site-association

Previously, the /.well-known/ path segment was optional, but the choice has now been deprecated.

以前,/.well-/路径段是可选的,但是现在不建议使用该选项。

It must also be available on https://.

它还必须在https://上可用。

You can only have a single version of this file, but there is different functionality offered for pre iOS13 and iOS13+. Luckily, the field names are different and these versions can coexist in the same file, enabling you to provide the improved functionality to your users who have updated their OS.

您只能拥有此文件的一个版本,但iOS13之前和iOS13 +提供了不同的功能。 幸运的是,字段名称不同,并且这些版本可以共存于同一文件中,从而使您能够为更新了操作系统的用户提供改进的功能。

iOS13之前的版本 (Pre iOS13)

The contents of this file, pre iOS13:

此文件的内容,iOS13之前的版本:

{
"applinks": {
"details": [
{
"appID": "{TEAM_ID}.{BUNDLE_ID}",
"paths": [
"*"
]
}
]
}
}

For each of your app Bundle IDs, you need a separate JSON object stating the appID and the paths that should be opened.

对于每个应用程序捆绑包ID,您需要一个单独的JSON对象,说明该appID和应打开的路径

The appID is your App Store Connect Team ID and your app’s Bundle ID separated by a full stop.

appID是您的App Store Connect团队ID和应用程序的Bundle ID,中间用句号分隔。

The paths are an array of URL paths that you want to handle for your app. You can have multiple paths, so you can be quite specific:

这些路径是您要为应用处理的URL路径的数组。 您可以有多个路径,因此可以很具体:

"/tv/tv-news/article-about-tv"

The above will open a specific path.

以上将打开一个特定的路径。

"/tv/tv-news/*"

The above uses the wildcard operator to instruct your application to open any URL whose path starts with “/tv/tv-news/”

上面使用通配符运算符指示您的应用程序打开任何路径以“ / tv / tv-news /”开头的URL

"*"

You can even use the wildcard operator to instruct your application to open every URL on your website.

您甚至可以使用通配符运算符来指示您的应用程序打开网站上的每个 URL。

iOS13以上 (iOS13+)

iOS13 brought changes to the format of the AASA file.

iOS13对AASA文件的格式进行了更改。

{
"applinks": {
"apps": [],
"details": [
{
"appIDs": ["{TEAM_ID}.{BUNDLE_ID}"],
"components": [
{
"/": "/tv/tv-news/*",
"comment": "Matches any URL whose path starts with /tv/tv-news/"
},
{
"/": "/celebrity/celebrity-news/*",
"exclude": true,
"comment": "Excludes any URL whose path starts with /celebrity/celebrity-news/"
}
]
}
]
}
}

Firstly appID has been replaced by appIDs, allowing you to supply an array of application IDs. This helps if you have multiple apps that follow the same URL matching rules.

首先APPID已取代appIDs,允许你提供的应用程序ID的数组。 如果您有多个遵循相同URL匹配规则的应用程序,这将很有帮助。

Secondly the paths components has been replaced by a components array, allowing for more explicit and ultimately more readable settings. Now for each path that you want to handle, you supply a JSON object with an optional comment, with the ability to set an exclude flag, to tell your application not to open URLs that match the supplied pattern.

其次, 路径组件已被组件数组取代,从而允许更明确的设置,并最终使设置更易读。 现在,对于要处理的每个路径,您都将提供一个带有可选注释的JSON对象,该注释具有设置排除标志的能力,以告诉您的应用程序不要打开与提供的模式匹配的URL。

More information on the available patterns can be found here.

有关可用模式的更多信息,请参见此处

设置应用程序委托 (Set up the App Delegate)

Inside your App Delegate you need to handle the incoming URLs your application has been instructed to open. This is handled, in Swift, by the following function:

在您的应用程序委托中,您需要处理已指示您的应用程序打开的传入URL。 在Swift中,这是通过以下函数处理的:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool

You are supplied a NSUserActivity object, which has two properties we want to look at.

为您提供了一个NSUserActivity对象,该对象具有我们要查看的两个属性。

webpageURL: The URL of the webpage to be opened

webpageURL :要打开的网页的URL

activityType: The type of activity that triggered this function call

activityType :触发​​此函数调用的活动类型

Inside this function, you should check that the activityType is set to NSUserActivityTypeBrowsingWeb, and that the webpageURL is definitely one that you want to handle.

在此函数内部,应检查activityType是否设置为NSUserActivityTypeBrowsingWeb ,以及webpageURL绝对是您要处理的URL

Once you have verified this, you can open the appropriate views inside of your application.

验证之后,您可以在应用程序内部打开相应的视图。

However, occasionally some URLs slip through the cracks that you do not want to open. In which case it is suggested that you should utilise UIApplication.open() to open the webpageURL or to open it within a SafariViewController.

然而,偶尔有些网址漏网之鱼裂缝,你不想打开。 在这种情况下,建议您应该使用UIApplication.open()打开webpageURL或到中打开它SafariViewController

这个怎么运作 (How it works)

Once you understand each of the components, the mystery around Universal Links quickly disappears.

一旦了解了每个组件,关于通用链接的谜团就会Swift消失。

When your application is installed on a device via Xcode build, TestFlight or from the App Store, iOS will attempt to download the AASA file from your website and store it on the device.

通过Xcode构建,TestFlight或从App Store将应用程序安装在设备上时,iOS将尝试从您的网站下载AASA文件并将其存储在设备上。

Once downloaded, any links that are tapped that match the patterns in your AASA file will be provided to your app to handle.

下载后,与您的AASA文件中的模式匹配的所有点击链接都将提供给您的应用程序进行处理。

It is possible your file will not be downloaded straight away if the device’s battery is low or there is a poor Internet connection. It will be retried periodically and any updates to your AASA file will be downloaded periodically in the same manner.

如果设备的电池电量不足或互联网连接不良,则可能不会立即下载文件。 它将定期重试,并且对AASA文件的任何更新将以相同的方式定期下载。

For this reason it is important to handle any website URLs on your website, for example if you are handling authentication URLs such as Forgotten Password links or Email Verification links.

因此,处理您网站上的任何网站URL都很重要,例如,如果您正在处理身份验证URL(例如“忘记密码”链接或“电子邮件验证”链接)。

Once an AASA file is downloaded, it will be associated with your application until it is deleted from the device.

下载AASA文件后,它将与您的应用程序相关联,直到将其从设备中删除为止。

调试 (Debugging)

If your universal links are not opening in your application, you can check the status of your downloaded AASA file by utilising Sysdiagnose. Using this tool you can check the logs of your application to verify the AASA file has been downloaded, and has been read correctly (e.g. no formatting issues).

如果您的应用程序中没有打开通用链接,则可以使用Sysdiagnose检查已下载的AASA文件的状态 。 使用此工具,您可以检查应用程序的日志,以验证AASA文件已下载并已正确读取(例如,没有格式问题)。

Validation of your AASA file could fail if the JSON is invalid, it doesn’t contain the application identifier, or the server provides with a non HTTP 200 OK response.

如果JSON无效,不包含应用程序标识符或服务器提供非HTTP 200 OK响应,则对AASA文件的验证可能会失败。

Your web URLs may also be ignored by iOS if your user long-presses a link and selects to open the URL with Safari via the menu shown below.

如果您的用户长按一个链接并选择通过以下菜单通过Safari打开URL,则iOS可能也会忽略您的Web URL。

URL tap menu
Opening with Safari will block future URLs from being opened until the user uses this menu in the future to select “Open in App”
使用Safari打开将阻止将来打开URL,直到将来用户使用此菜单选择“在应用程序中打开”

If you are updating your AASA file during development, deleting the application from your device between updates will enable you to see your changes immediately.

如果在开发过程中更新AASA文件,则在两次更新之间从设备中删除该应用程序将使您能够立即看到所做的更改。

One final note, as of iOS14, Apple will host your AASA files on their own CDN, which should improve downloading of the file, but could see some issues arise with TTLs.

最后一点,从iOS14开始,苹果会将您的AASA文件托管在自己的CDN上,这会改善文件的下载,但可能会发现TTL出现一些问题。

结论 (Conclusion)

Universal Links are a great tool to provide improved native experiences for accessing your content and more seamless experiences for interactive functionality such as authentication flows. You need to ensure you can handle the functionality on your website (1–3% of requests will bypass Universal Links for assorted reasons), but the resulting functionality should improve your user’s experience with your application and brand.

通用链接是一种出色的工具,可提供改进的原生体验来访问您的内容,并为交互功能(例如身份验证流程)提供更无缝的体验。 您需要确保可以处理网站上的功能(出于各种原因,有1-3%的请求将绕过通用链接),但是最终的功能应改善用户对应用程序和品牌的体验。

翻译自: https://medium.com/trinity-mirror-digital/how-we-use-universal-links-to-provide-a-seamless-login-experience-bc1ac946deea

未发布的ios应用程序链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值