我正在App.js中使用以下代码-componentDidMount
firebase
.dynamicLinks()
.getInitialLink()
.then(link => {
if (link) {
if (link.url.includes('/s/')) {
this.handleSignupURL(link.url)
}
}
})
firebase.dynamicLinks().onLink(({ url }) => {
if (url && url.includes('/s/')) {
this.handleSignupURL(url)
}
})
}
在单击动态链接时:当应用程序处于活动状态时,将触发onLink处理程序,并由应用程序正确处理。但是,当应用程序关闭时,getInitialLink返回null。有什么方法可以获取初始链接?
我正在使用react-native-firebase v6,对应于expo 36的react-native。安装是按照新的react-native-firebase quick start执行的。我正在使用iOS应用。
答案 0 :(得分:2)
我现在也在iOS上遇到此问题。我不确定这是否是一个好的解决方法,因为我尚未交付生产,但是当应用程序不在后台时,我可以在iOS上正常工作的一种方法是使用RN中的链接包,例如在我的启动屏幕中:
Linking.getInitialURL().then((url) => {
if (url){
Linking.openURL(url).then((response) => {
Actions.reset('MainFeed');
});
} else {
console.log('no url');
Actions.reset('MainFeed');
}
});
然后在MainFeed屏幕上的componentDidMount上,为onLink设置一个侦听器。由于我们现在在应用程序打开时正在调用openURL,因此firebase的onLink会触发,并且我能够解析深层链接并将用户路由到他们需要去的地方。
我尚未测试此方法是否允许链接持久保存应用商店的安装
编辑:我已经对此进行了测试,并且一直有效。该链接通过应用商店/ Google Play下载而保持不变