iOS 通用链接

参考链接:http://www.jianshu.com/p/734c3eff8feb

参考链接:http://blog.csdn.net/kuangdacaikuang/article/details/52958052?locationNum=12&fps=1

参考链接:http://www.cnblogs.com/ysk-china/p/5777299.html

参考链接:https://www.jianshu.com/p/8e8840dcd54d

参考链接:https://blog.branch.io/3-steps-to-troubleshoot-ios-9-and-ios-10-universal-links/

文档链接:https://developer.apple.com/library/content/documentation/General/Conceptual/AppSearch/UniversalLinks.html#//apple_ref/doc/uid/TP40016308-CH12-SW1

下面是文档学习:

1、get seamlessly redirected to your installed app without going through Safari.If your app isn’t installed ,tapping a link to your website opens your website in Safari.

无需经过Safari无缝到达你已经安装好的app,如果你的app没有安装,触发网站的链接会在safari打开你的网站。

2、Unique — Unlike custom URL schemes, universal links can’t be claimed by other apps, because they use standard HTTP or HTTPS links to your website.

独特性:不像定制的url方案,通用链接不能被其他app声明,因为他们使用标准的http或者https链接给你的网站。

3、Secure —  When users install your app, iOS checks a file that you’ve uploaded to your web server to make sure that your website allows your app to open URLs on its behalf. Only you can create and upload this file, so the association of your website with your app is secure.

安全性—当你安装你的app的时候,iOS检查一个你已经上传到你的web服务器的文件来确保你的网站以你自己的行为打开你的URL,一旦你创建和上传这个文件,你的网站跟你的app的联系是安全的。

4、 Flexible———Universal links work even when your app is not installed. When your app isn’t installed, tapping a link to your website opens the content in Safari, as users expect.

即使你的app没有安装,通用的链接也能工作,当你的app没有安装的时候,点击你网站的链接会如用户期盼的一样会打开你在Safari上的内容。

5、Simple — One URL works for both your website and your app.

简单 :一个url对你的网站和app都工作。

6、 Private ——Other apps can communicate with your app without needing to know whether your app is installed.

私密性:其他apps能跟你的app进行联系,不需要知道你的app是否已经安装。

7、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.

通用的链接让你的用户在WKWebView和UIWebView内点击那些链向网站的链接打开你的app,除此之外还有那些引导调用openURL的链接,例如邮件、消息、和其他app。

8、When a user is browsing your website in Safari and they tap a universal link to a URL in the same domain as the current webpage, iOS respects the user’s most likely intent and opens the link in Safari. If the user taps a universal link to a URL in a different domain, iOS opens the link in your app.

当一个用户正在浏览你的网站,他们在目前的网页在相同的域点击一个指向URL的链接时,iOS系统会反应用户最可能的意图而在safari中打开链接,如果用户在不同的域点击一个指向url的通用链接,iOS 在你的app中打开链接。

9、For users who are running versions of iOS earlier than 9.0, tapping a universal link to your website opens the link in Safari.

对于那些使用早于9.0版本的iOS系统的手机,点击一个指向网站的通用的链接会让你在Safari中打开链接。

10、thre steps you need to take

11、Create an apple-app-site-association file that contains JSON data about the URLs that your app can handle.

创建一个包含关于urls的jsondata的apple-app-site-assoociation文件,这些urls你的app能处理。

12、Upload the apple-app-site-association file to your HTTPS web server. You can place the file at the root of your server or in the .well-known subdirectory.

将这个文件上传到你的https web 服务器,你能将这个文件放到你的服务器的根目录,或者.well-known目录。

13、Prepare your app to handle universal links.

做准备让你的app处理通用的链接。

14、In your apple-app-site-association file, you specify the paths from your website that should be handled as universal links along with those that should not be handled as universal links. Keep the list of paths fairly short and rely on wildcard matching to match larger sets of paths. 

在这个文件中,你指定你的网站的路径,这些路径会被作为通用路劲处理,也会作为不是通用的路径处理。保持这些路径很短,依赖这些通配符匹配更大的路径集合。

15、Don’t append .json to the apple-app-site-association filename.

不要将.json作为这个文件的名字。

16、apple-app-site-association文件格式

{   

   “applinks”: {

      “apps”:[],

      “details”:[

         {

           “appid”: “9ja89qqlnq.com.apple.wwdc”,

           “paths”: [“/wwdc/news/”, “/videos/wwdc/2015/*”]

         },

         { 

           “appid”:”abcd1234.com.apple.wwdc”,

           “paths”:[“*”]

         }

      ]

   }

}(

 appID:组成方式是 teamId + .bundle identifier(注意点号)。登陆开发者中心,在Account - Membership里面可以找到Team ID

17、The apps key in an apple-app-site-association file must be present and its value must be an empty array, 

在文件apple-app-site-association中的apps必须有,且他的值是一个空的数组。

18、The value of the details key is an array of dictionaries, one dictionary per app that your website supports

这个detail key对相应对应的是一个字典数组,你的网站支持的每个app的字典。

19、The order of the dictionaries in the array determines the order the system follows when looking for a match, so you can specify an app to handle a particular part of your website.

当他们匹配的时候,在数组的字典的顺序决定系统跟随的顺序,你能指定一个app来处理你的网站特殊的部分。

20、The value of the appID key is the team ID or app ID prefix, followed by the bundle ID.

appid的值是一个teamID或者app id 前缀,被bundle id接着。

21、The appID value is the same value that’s associated with the “application-identifier” key in your app’s entitlements after you build it

在你建立后,appid值是相同的值,这个值跟你app的权利中的application-identifier值一样。

22、 The value of the paths key is an array of strings that specify the parts of your website that are supported by the app and the parts of your website that you don’t want to associate with the app.

paths键的值是一个字符串数组,这些指定你支持app的部分网站,以及不支持你的app的部分网站。

23、 To specify an area that should not be handled as a universal link, add “NOT ” (including a space after the T) to the beginning of the path string. 

哪些区域不应该收到处理的,在这个路径的开头加NOT。

24、 . "paths": [ "/wwdc/news/", "NOT /videos/wwdc/2010/*", "/videos/wwdc/201?/*"]

This could prevent the /videos/wwdc/2010/* area of the website from being handled as a universal link 

通过这么添加,能阻止网站的/videos/wwdc/2010/*区域被作为一个通用的链接处理

25、Because the system evaluates each path in the paths array in the order it is specified—and stops evaluating when a positive or negative match is found—you should specify high priority paths before low priority paths. Note that only the path component of the URL is used for comparison. Other components, such as the query string or fragment identifier, are ignored.

因为系统会按顺序评估path数组里面的每个路径,并且当看到一个正的或者负的匹配被发现时停止评估。你应该在低优先路径前指定高优先路径,URL中唯一那个path组件用来比较,其他的组件例如咨询或者碎片标识符,被忽视。

26、Use * to specify your entire website使用 *来制定你的全部的网站。

27、Include a specific URL, such as /wwdc/news/, to specify a particular link包含一个特殊的URL,例如,/wwdc/news/,来指定一个特殊的链接。

28、Append * to a specific URL, such as /videos/wwdc/2015/*, to specify a section of your website

通过 /videos/wwdc/2015/*来指定你的网站的章节。

29、In addition to using * to match any substring, you can also use ? to match any single character. You can combine both wildcards in a single path, such as /foo/*/bar/201?/mypage.

为了应用*来匹配任何下字符串,你也能用?来匹配任何简单的符号,你能将两个联系在一起。

30、Preparing your app to handle Universal links.

 When a user taps a universal link, iOS launches your app and sends it an NSUserActivity  object that you can query to find out how your app was launched.

当一个用户点击一个通用的链接的时候,iOS 发起那个app,并且给这个app发送一条object信息,你能咨询找到你的app是怎么发起的。

31、Add an entitlement that specifies the domains your app supports.

增加一个权利,指定你的app支持的域。

32、Update your app delegate to respond appropriately when it receives the NSUserActivity object.

当它收到NSUserActivity 对象的时候,更新你的app代理来合适的反应。

33、To do this in Xcode, open the Associated Domains section in the Capabilities tab and add an entry for each domain that your app supports, prefixed with applinks:, such as applinks:www.mywebsite.com. Limit this list to no more than about 20 to 30 domains.

为了在xcode里面做这个,在Capabilties栏的Associated Domains处为每个domain添加一个支持你app的入口,以applinks为前缀,例如这个,pplinks:www.mywebsite.com,限制这个列表不要超过20到30个。

34、To match all subdomains of an associated domain, you can specify a wildcard by prefixing *. before the beginning of a specific domain (the period is required).

为了匹配一个关联的域的子域,你能通过一个*.在你特定域前指定一个通配符,*.是必须要的。

35、Domain matching is based on the longest substring in the applinks entries. 

域名匹配是在appLinks入口基于最长的子字符串。

36、等你添加域之后,你应该事先applicationDelegate里面的- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler {

    return YES;

}方法,以至于能让你的app收到一个链接以及合适地处理它。

37、When iOS launches your app after a user taps a universal link, you receive an NSUserActivity object with an activityType value of NSUserActivityTypeBrowsingWeb . The activity object’s webpageURL property contains the URL that the user is accessing. The webpage URL property always contains an HTTP or HTTPS URL, and you can use NSURLComponents APIs to manipulate the components of the URL.

在一个用户点击一个通用的链接,iOS系统唤起你的app,你收到一个userActivity 对象,这个对象拥有

NSUserActivityTypeBrowsingWeb 类型的活动值,这个对象的webpageUrl属性包含用户正去接近的url,webpage url属性也包含一个http或者https 的URL。

38、When a user taps a universal link that you handle, iOS also examines the user’s recent choices to determine whether to open your app or your website. 

当一个用户点击一个你处理的通用的链接的时候,iOS 也要去检查这个用户最近的选择以便决定是否打开你的app或者网站。

39、For example, a user who has tapped a universal link to open your app can later choose to open your website in Safari by tapping a breadcrumb button in the status bar. After the user makes this choice, iOS continues to open your website in Safari until the user chooses to open your app by tapping OPEN in the Smart App Banner on the webpage.

例如,一个点击那个通用链接的用户,为了以后再打开app,他通过点击status bar上面的痕迹按钮来打开这个网站,在用户做选择后,iOS继续打开你的网站,直到用户在webpage上选择打智能app条。

40、If you instantiate a SFSafariViewController,WKWebView,or WKWebView  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或WKWebView来处理通用链接,iOS系统代替打开app而是打开网页,然而,如果这个用户点击一个嵌入的SFSafariViewController、WKWebView、UIWebView对象

,iOS将打开app.

41、It’s important to understand that if your app uses openURL: to open a universal link to your website, the link does not open in your app. In this scenario, iOS recognizes that the call originates from your app and therefore should not be handled as a universal link by your app.’

这是非常重要的,如果你的app使用openURL来打开你的网站的一个通用链接,这个链接不去打开你的app,在这个章节,iOS知道这个调用来自你的app,因此不应该作为通用链接被你的app来处理。

42、If you receive an invalid URL in an activity object, it’s important to fail gracefully. To handle an unsupported URL, you can call openURL:on the shared application object to open the link in Safari. If you can’t make this call, display an error message to the user that explains what went wrong.

如果你在一个活动对象中收到一个无效的URL,为了处理一个不支持的url,为了处理一个通用的url,你在公共分享对象中调用openURL来打开那个链接,如果你不能调用那个,将会展示一个错误以便提醒用户。

43、To protect users’ privacy and security, you should not use HTTP when you need to transport data; instead, use a secure transport protocol such as HTTPS.

为了保护用户隐私,你应该不要使用http,而是用https

44、注意,要让你的app有这个功能,首先还得去开发者打开相应的功能。将Associated Domains设置为Anabled.

特别注意:

1、触发的链接一定要包含域名

2、测试的时候会出现有时候能点开有时候不能点开的情形,这个时候你要删掉app,然后重新开始。

测试工具1:

https://branch.io/resources/aasa-validator/

测试工具2:

https://search.developer.apple.com/appsearch-validation-tool

饿了么出现的问题:

https://github.com/eleme/mobilists/blob/master/source/_posts/%E7%AA%81%E7%A0%B4%E5%BE%AE%E4%BF%A1%E8%B7%B3%E8%BD%AC%E9%99%90%E5%88%B6%EF%BC%8DUniversal-Links%E9%82%A3%E4%BA%9B%E5%9D%91.md

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值