如何在收到fcm推送通知时打开处于退出状态的应用程序-REACT NATIVE



计划构建一个像uber这样的应用程序,我们有两个应用程序,一个用于最终用户,另一个用于司机,如果最终用户发送预订通知,我们需要在司机应用程序推送通知中显示为"取消"one_answers"接受"按钮,声音类似铃声,或者如果应用程序处于退出状态或后台状态,我们需要自动打开应用程序。使用的技术:-反应天然,燃烧基地。请帮我解决问题,我热切地等待你的宝贵建议和想法

https://0x1bitcrack3r.medium.com/incoming-call-notifications-for-react-native-apps-ef4725702401-使用这个博客,我可以更改推送通知ui,并可以触发铃声,比如whats应用程序调用

useEffect(() => {
// Assume a message-notification contains a "type" property in the data payload of the screen to open
messaging().onNotificationOpenedApp(remoteMessage => {
console.log(
'Notification caused app to open from background state:',
remoteMessage.notification,
);
navigation.navigate('TransactionWithNotification', remoteMessage);
});
// Check whether an initial notification is available
messaging()
.getInitialNotification()
.then(remoteMessage => {
if (remoteMessage) {
console.log(
'Notification caused app to open from quit state:',
remoteMessage.notification,
);
navigation.navigate('TransactionWithNotification', remoteMessage);
}
setLoading(false);
});
messaging().onMessage(async remoteMessage => {
console.log('Notification foregorund state:', remoteMessage);
navigation.navigate('TransactionWithNotification', remoteMessage);
});
}, []);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

我建议你去https://rnfirebase.io/使用此功能,您可以拥有一个节点应用程序或使用firebase功能将通知推送到已注册的设备在这里您可以使用以下

onNotificationOpenedApp:当用户按下通过FCM显示的通知时,如果应用程序已从后台状态打开,则会调用此侦听器。https://rnfirebase.io/reference/messaging

onNotificationOpenedApp(listener: (message: RemoteMessage) => any): () => void;

相关内容

最新更新