Dev*_*Rao 0 hybrid-mobile-app reactjs react-native firebase-cloud-messaging
我在我的React Native应用程序中将react-native-firebase库用于FCM功能。我遵循了他们网站https://rnfirebase.io/docs/v4.2.x/installation/initial-setup上提供的初始指南。我还为Android设置了Cloud Messaging and Notifications模块。通知正确到达设备。但是,问题是单击通知后,我无法路由到特定屏幕。我正在使用react-navigation库进行导航。我实际上对React本机非常陌生,所以我不知道如何为该功能编写代码。任何帮助表示赞赏。最主要的是我很困惑应该在哪里编写导航代码。另外,即使应用程序关闭并单击通知,我也希望它能正常工作。
如何在反应导航中设置深层链接:https : //reactnavigation.org/docs/en/deep-linking.html
如何设置通知以触发深层链接:
handleNotification (notification) {
const { data } = notification;
const prefix = Platform.OS === 'android'
? 'myapp://myapp/'
: 'myapp://'
const url = `${prefix}${data.path}/${data.id}`;
if (notification.data.path) {
Linking.openURL(url).catch(err => console.error(err));
firebase.messaging().setBadgeNumber(0);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1630 次 |
| 最近记录: |