React Native中点击Notifee通知无法唤起APP的问题求助
React Native中点击Notifee通知无法唤起APP的问题求助
我现在在做React Native项目,用Notifee配合Firebase Messaging实现推送通知功能,结果碰到个棘手的问题:点击通知没法唤起APP,具体情况如下:
问题出现的场景
- 当APP处于后台运行状态时
- 当APP被完全退出(杀死进程)状态时
这两种场景下,通知都能正常收到,但只要一点击通知,通知就直接消失了,APP却依然处于关闭/后台状态,完全没被唤起。
我的index.js代码
/** * @format */ import {AppRegistry} from 'react-native'; import 'react-native-get-random-values'; import 'react-native-url-polyfill/auto'; import {ReadableStream} from 'web-streams-polyfill'; import notifee, {AndroidImportance, AndroidStyle, EventType} from '@notifee/react-native'; import messaging from '@react-native-firebase/messaging'; import App from './App'; import {name as appName} from './app.json'; globalThis.ReadableStream = ReadableStream; // Register background handler const displayNotification = async remoteMessage => { }; messaging().setBackgroundMessageHandler(async remoteMessage => { console.log('Message handled in the background! na', remoteMessage); displayNotification(remoteMessage); }); notifee.onBackgroundEvent(async ({type, detail}) => { if (type === EventType.ACTION_PRESS) { console.log('Notification clicked in background new:', detail); global.notificationData = detail; } }); messaging() .getInitialNotification() .then(remoteMessage => { if (remoteMessage) { console.log('Notification clicked in quit state:', remoteMessage); global.notificationData = remoteMessage.data; } }); AppRegistry.registerComponent(appName, () => App);
我用的推送消息格式(data-only类型)
{ "collapseKey": "xxx.xxxx.xxx", "data": { "actions": "", "body": "50% off on your next purchase. Don't miss out!", "image": "https://www.shutterstock.com/image- photo/coronavirus-quarantine-stop-concept-man-260nw-1705838560.jpg", "priority": "high", "title": "test new 1 Special Offer!" }, "from": "383197575644", "messageId": "0:1735644817570165%0a88414a0a88414a", "originalPriority": 1, "priority": 1, "sentTime": 1735644817560, "ttl": 2419200 }
我本来以为通过notifee.onBackgroundEvent处理后台的通知点击,用getInitialNotification处理APP退出状态的点击,就能唤起APP并传递数据,但现在完全没效果,点击通知后APP就是不启动,有没有大佬知道这是哪里出问题了?
备注:内容来源于stack exchange,提问作者Manish Kumar
相关产品推荐
相关产品推荐

