Universal Link的优先权

  • It is usual to use one universal link in one app.
  • It is also usual to use one universal link in one app for different scheme witch is using different bundle Id.
  • But it is unusual for mutable apps installed in the same device which are using mutable universal link in different priority.

For QA Testing, we’re setting someDebug,InHouse,Release-Candidate into apple-app-site-association.There’s no problems happened befor, because users can’t install a Debug version, and also the test device did not have to install a life version.

If you already know what isuniversal linkyou can skip this part
If you don’t know what isuniversal linkyou should read this apple’s doc first =>
clickMe
And this is a simple description↓

universal linkis a technique that can make your apps wake up and deep linking to a target page while user click some normal url like https://shaggon.com/man/322113 in safari,mail,message or social media apps.

  • There’re only two steps to implementationuniversal link

    1. Add the domain(for example: applinks:shaggon.com) in Capabilities => Associated Domains
    2. Add a file namedapple-app-site-association at the root of the server, make sureshaggon.com/apple-app-site-associationis visible. content is like below↓
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    {
    "applinks": {
    "apps": [],
    "details": [
    {
    "appID": "9JA89QQLNQ.com.apple.wwdc",
    "paths": [ "/wwdc/news/", "/videos/wwdc/2015/*"]
    },
    {
    "appID": "ABCD1234.com.apple.wwdc",
    "paths": [ "*" ]
    }
    ]
    }
    }

The priority

Let’s back to the question

mutable apps installed in the same device which are using mutable universal link in different priority

We can find this in apple’s Doc:

The value of the details key is an array of dictionaries, one dictionary per app that your website supports. 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.

It looks like we can adjust the priorities of the dictionary inside the array of details to make that work.
Let’s try it!

  • PREPARE
    • https://shaggon.com/apple-app-site-association <– A First
    • https://www.doruby.com/apple-app-site-association <– B First
    • A clean Simulator iPhone 7
    • Installed app A
    • Installed app B
  • TEST


















Device installed A&B Device installed A Only Device installed B Only
A First A Opened A Opened B Opened
B First B Opened A Opened B Opened

CONCLUSION

Just like apple’s doc said,universal linkdose have the priority for different apps, what you need to do is to change the order of the different apps inside the array of detail.


  • 一个app使用一个universal link很普遍
  • 一个app的多个使用不同bundle Id的scheme共用一个universal link也很常见
  • 多个app使用多个universal link且在同时安装多个app的设备上需要保证不一样的link实现不一样的跳转优先级这个就不常见了。

我们天生的会把Debug,InHouse,Release-Candidate等的记录填写在apple-app-site-association中,以供QA在测试机上使用。我们没有发生过任何问题,因为正式用户不可能安装任何非life版本,而测试机也不怎么安装life版本。

如果你已经知道universal link是什么的话可以先略过这一部分
如果你不明白什么是universal link你可以先阅读这份苹果的文档 =>
点我
然后下面是一份简单浅显的说明↓

universal link是一种可以让iOS用户通过在浏览器、邮件、短信、或社交软件中点击一个普通的url例如https://shaggon.com/man/322113而直接唤醒app并深度链接到指定页面的技术。

  • 实现universal link只需要做两步

    1. 在工程的Capabilities => Associated Domains中加入domain名字,例如applinks:shaggon.com
    2. 在domain所对应的网站根目录下添加如下的一个名叫apple-app-site-association的文件,使得shaggon.com/apple-app-site-association可供访问。内容如下↓需要关注和修改的点在details下面的一个包含着多个字典的数组中,它用来描述这个universal link的哪些path被哪个team的哪个bundleID的app所支持。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    {
    "applinks": {
    "apps": [],
    "details": [
    {
    "appID": "9JA89QQLNQ.com.apple.wwdc",
    "paths": [ "/wwdc/news/", "/videos/wwdc/2015/*"]
    },
    {
    "appID": "ABCD1234.com.apple.wwdc",
    "paths": [ "*" ]
    }
    ]
    }
    }

优先级问题

让我们再次回到问题

多个app使用多个universal link且在同时安装多个app的设备上需要保证不一样的link实现不一样的跳转优先级

苹果的文档中我们可以发现这样一句话:

The value of the details key is an array of dictionaries, one dictionary per app that your website supports. 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.

看起来我们可以通过在details这个数组中调整内容的优先顺序来达到目的。
那到底行不行呢?我们来测测看。

  • 准备
    • https://shaggon.com/apple-app-site-association <– A First
    • https://www.doruby.com/apple-app-site-association <– B First
    • A clean Simulator iPhone 7
    • Installed app A
    • Installed app B
  • 测试


















Device installed A&B Device installed A Only Device installed B Only
A First A Opened A Opened B Opened
B First B Opened A Opened B Opened

结论

就如苹果文档中所说的那样,universal link是存在跳转的优先级的,只需要修改details这个数组中的内容的顺序即可。