Universal Link 实施步骤

2022-07-16  本文已影响0人  BlueSky_a63f

Universal Link 实施步骤

当我们使用URL scheme 从web网页启动APP时,如果APP未安装,会提示出错,打断用户操作,从APP使用URL Scheme跳转另一个APP时如果该APP没有安装,也会跳转失败。

如果APP支持Universal Link,就可以实现APP和web网页间的顺滑衔接。也可实现APP间的跳转,不再依赖URL Scheme。

当从Web网页打开支持Universal Link的链接时,如果有安装相应APP,则会直接跳转到APP继续操作,如果没有安装,也能正常的打开网页链接,不会报错。

当从APP使用UIApplication.shared.open()方法打开一个支持Universal Link 的URL时也是同样的,如果安装了支持该Universal Link的APP则直接启动APP,如果没有安装,则会打开相应的网页。大大的改善了用户体验。

服务器配置

Apple账号配置

image-20201129211002922.png

Xcode工程配置

image-20201129213934410.png

使用Universal Link

Universal Link注意点

  1. Universal Link跨域

    当在web网页使用Universal Link时有跨域问题,Universal Link 必须要求跨域,如果不跨域,就不会跳转(iOS 9.2之后的改动) 。假如当前网页的域名是A,当前网页发起跳转的域名是B,必须要求BA是不同域名才会触发Universal Link,如果BA是相同域名,只会继续在当前WebView里面进行跳转,哪怕你的Universal Link一切正常,根本不会打开App

  2. iOS 系统请求apple-app-site-association配置文件的时机

    • 当我们的App在设备上第一次运行时,如果APP支持Associated Domains功能,那么iOS会自动通过GET方式请求定义在Xcode工程配置 Domains 域名下的 apple-app-site-association 文件

    • iOS会先请求https://xxx.com/.well-known/apple-app-site-association,如果此文件请求不到,再去请求根目录https://xxx.com/apple-app-site-association,所以如果想要避免服务器接收过多GET请求,可以直接把apple-app-site-association放在./well-known目录下

    • 服务器上apple-app-site-association的更新不会让iOS本地的apple-app-site-association同步更新,即iOS只会在App第一次启动时请求一次,以后除非App更新或重新安装,否则不会在每次打开时请求apple-app-site-association

上一篇 下一篇

猜你喜欢

热点阅读