我想实现在与Firebase发送的推送通知交互时打开特定的屏幕。我的理解是,我需要使用在react-native-firebase v5和更低版本中可用的getInitialNotification()函数,但在react-native-firebase v6中还不可用,因为通知包还没有准备好。其中,到目前为止,我已经尝试设置了云消息包中提供的后台消息处理程序,但它似乎不适用于非data-only消息:
Firebase.messaging().setBackgroundMessageHandler(async (remoteMessage) => { await storeJSONData('notification', JSON.stringify(remoteMessage)); });
我应该降级到react-native-firebase v5来使用他们的通知包中的getInitialNotification()吗,或者我还有其他更好的选择,比如使用android原生代码吗?
发布于 2019-11-28 21:36:09
我最终通过在firebase云消息传递之上使用react-native-push-notification包并从该包实现onNotification函数解决了这个问题。
PushNotification.configure({
onNotification: function(notification)
{
// process the notification
console.log('NOTIFICATION:', notification);
//iOS only
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true,
});https://stackoverflow.com/questions/58709750
复制相似问题