本文介绍内容
一、Universal Links 介绍
二、如何配置 Universal Links
三、微信分享如何配置 Universal Links
一、Universal Links 介绍
通过 Universal Links 是在浏览器 safari 或者 webview 中是可以直接打开(或者叫跳转到) APP 的。
查看苹果文档
Universal Links 有 5 个好处
- 唯一性:不像自定义的 schema 链接,通用链接不会被其它的 App 所使用。因为它使用标准的 https 链接到你自己的域名
- 安全性:当用户下载 App 的时候,iOS 会检查你上传到 web 服务器的文件以确保您的网站允许您的应用程序以其名义打开网址。因为只有本人有权利创建且上传该文件到服务器,所以网站和 App 的关联是安全的。
- 灵活性:甚至在 iOS 设备没有安装你项目的时候通用链接也会正常工作。当设备没有安装 App 的时候,点击通用链接会在 Safari 展示你网站的内容。
- 简单:一个通用链接可以同时作用于项目和网站中。
- 私有的/独立的?:其它 App 可以在不知道你的 App 是否安装的情况下与你的App 通信
二、如何配置 Universal Links
1)编辑一个 apple-app-site-association
apple-app-site-association 是一个 json 文件,没有 .json 后缀的
例子:
{
"applinks":{
"apps":[
],
"details":[
{
"appID":"9JA89QQLNQ.com.apple.wwdc",
"paths":[
"wwdc/*"
]
},
{
"appID":"9JA89QQLNQ.com.apple.demo02",
"paths":[
"/demo01/*",
"/qq_conn/11111111/*"
]
},
{
"appID":"9JA89QQLNQ.com.apple.demo02",
"paths":[
"/demo02/*",
"/qq_conn/2222222/*"
]
}
]
}
}
注释:
- AppID:固定格式,由 TeamID.Bundle Identifier 组成。TeamID 可在 苹果开发者后台的 Membership 查看,Bundle Identifier 项目的 包名。
- paths:设定一个 App 的路径支持列表,只有这些指定的路径链接才会被App所处理。(paths是大小写敏感,*是通配符表示任意路径,一般填写这个就可以。但是建议设置至少一个路径。不然全域名下的链接都会跳转到App 内部,可能不符合我们的预期的)
2)将 apple-app-site-association 文件放到 https 服务端的根目录或者 .well-known 目录下
例子:
https://
https://
在浏览器可以查看和浏览
https://
https://
大家可以查看下微信的例子:
https://help.wechat.com/apple-app-site-association
3)通过一下的链接地址可以检测 json 文件的是否可行
https://search.developer.apple.com/appsearch-validation-tool/
将 https://
4)如果域名是 linktest.com
那么 上面的 apple-app-site-association 对应的 Universal Links 就是
https://linktest.com/wwdc/
5)Xcode 中的配置
在 target -> Signing & Capabilities -> Associated Domains里面添加 applinks:linktest.com
6)在 developer.apple.com 后台创建的 AppID 的时候,勾选 Associated Domains
三、微信分享如何配置 Universal Links
1)首先编辑 apple-app-site-association json 文件,放到域名目录下面
个人建议是要加入 path 目录,不要只用 * 号替代。
{
"applinks": {
"apps": [],
"details": [
{
"appID": "9JA89QQLNQ.com.apple.wwdc",
"paths": [ "wwdc/*"]
},
{
"appID": "xxxxxxxxx.com.apple.news",
"paths": [ "news/*"]
},
]
}
}
2)在微信 的后台需要配置 Universal Links 也就是如下的
com.apple.wwdc App 的 Universal Links 为
https://linktest.com/wwdc/
com.apple.news App 的 Universal Links 为
https://linktest.com/news/
3)一个域名支持多个应用吗?是支持的。
可以查看的微信的例子中就配置了多个包名,具体查看
https://help.wechat.com/apple-app-site-association
具体可以查看微信的文档。
4)微信分享的时候 Universal Links 在微信后台和 Xcode 里面的 要一致。