react-native-firebase 通知中的深层链接 [英] Deep links in react-native-firebase notifications
问题描述
我正在使用 react-native-firebase 和消息传递向我的应用程序发送通知,使用云功能,使用 admin.messaging().send(message),与此处非常相似:https://medium.com/the-modern-development-stack/react-native-push-notifications-with-firebase-cloud-functions-74b832d45386 .
I am using react-native-firebase with messaging to deliver notifications to my app with cloud functions, with admin.messaging().send(message), very similar to here: https://medium.com/the-modern-development-stack/react-native-push-notifications-with-firebase-cloud-functions-74b832d45386 .
当应用程序在后台时,我会收到通知.现在我正在通知正文中发送文本,例如已将新位置添加到地图中".我希望能够添加某种深层链接,以便当我在通知上滑动视图时(例如在 iOS 上),它会将我带到应用程序内的特定屏幕.如何将数据从通知传递到应用程序?
I receive notifications when the app is in the background. Right now I am sending a text in the body of the notification, like 'a new location has been added to the map'. I want to be able to add some sort of deep link, so that when I swipe View on the notification (on iOS for example), it will take me to a specific screen inside the app. How do I pass data from the notification to the app?
我在应用中使用 react-native-navigation.我只能从应用程序内部找到有关深层链接的代码(https://wix.github.io/react-native-navigation/#/deep-links?id=deep-links).
I am using react-native-navigation in the app. I can only find code about deep links from inside the app (https://wix.github.io/react-native-navigation/#/deep-links?id=deep-links).
推荐答案
我的解决方案是使用在通知消息对象的数据对象中添加我需要的信息:
My solution was to use add what information I need in the data object of the notification message object:
在函数/index.js 中:
in functions/index.js:
let message = {
notification: {
body: `new notification `
},
token: pushToken,
data: {
type: 'NEW_TRAINING',
title: locationTitle
}
};
并在导航应用程序中进行如下处理:
and process as follows in the app for navigation:
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
});
}
这篇关于react-native-firebase 通知中的深层链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!