IOS
UniversalLinks 与微信 sdk 接入
- 注册的 link 需为域名本身,不能带相对路径
- apple-app-site-association 要按照最新文档来,和之前的有出入
{
"applinks": {
"details": [
{
"appIDs": [ "xxx.babylon.lianmeihu.com" ],
"components": [{
"/": "/",
"comment" : "anything"
},{
"/": "/*",
"comment" : "anything"
}]
}
]
}
}
- 手机测试
- 使用 Safari 浏览器
- 打开手机的 「开发者 > 关联域开发」
- ios 路由唤起
- 因为 ReactNative 实质在一张页面下,所以需要从 initialUrl 处分析
componentDidMount(){
// this handles the case where the app is closed and is launched via Universal Linking.
Linking.getInitialURL()
.then((url) => {
if (url) {
// Alert.alert('GET INIT URL','initial url ' + url)
this.resetStackToProperRoute(url)
}
})
.catch((e) => {})
// This listener handles the case where the app is woken up from the Universal or Deep Linking
Linking.addEventListener('url', this.appWokeUp);
}
componentWillUnmount(){
// Remove the listener
Linking.removeEventListener('url', this.appWokeUp);
}
appWokeUp = (event) => {
// this handles the use case where the app is running in the background and is activated by the listener...
// Alert.alert('Linking Listener','url ' + event.url)
this.resetStackToProperRoute(event.url)
}
resetStackToProperRoute = (url) => {
// Do Whatever you need to do within your app to redirect users to the proper route
}