Nic*_*pes 4 react-native react-native-navigation react-native-firebase
我使用带有消息传递功能的react-native-firebase通过云功能向我的应用程序传递通知,使用admin.messaging().send(message),与这里非常相似: https: //medium.com/the-modern-development -stack/react-native-push-notifications-with-firebase-cloud-functions-74b832d45386。
当应用程序在后台时我会收到通知。现在,我正在通知正文中发送一条文本,例如“新位置已添加到地图中”。我希望能够添加某种深层链接,这样当我在通知上滑动视图(例如在 iOS 上)时,它会将我带到应用程序内的特定屏幕。如何将数据从通知传递到应用程序?
我在应用程序中使用react-native-navigation。我只能从应用程序内部找到有关深层链接的代码(https://wix.github.io/react-native-navigation/#/deep-links?id=deep-links)。
我的解决方案是在通知消息对象的数据对象中添加我需要的信息:
在函数/index.js 中:
let message = {
notification: {
body: `new notification `
},
token: pushToken,
data: {
type: 'NEW_TRAINING',
title: locationTitle
}
};
Run Code Online (Sandbox Code Playgroud)
并在导航应用程序中进行如下处理:
this.notificationOpenedListener =
firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
if (notification.data.type === 'NEW_TRAINING') {
this.props.navigator.push({
screen: 'newtrainingscreen',
title: notification.data.title,
animated: true
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10302 次 |
| 最近记录: |