我在使用本地 react-native-push-notification 时遇到问题,如果应用程序处于打开状态且 fcm 通知未触发,则无法正常工作。这是我的代码...
PushNotification.configure({
onRegister: function (token) {
console.log("[LocalNotificationService] onRegister:", token);
},
onNotification: function (notification) {
console.log("[LocalNotificationService] onNotification:", notification);
if (!notification?.data) { return }
// notification.userInteraction = true;
if(notification.userInteraction){ onOpenNotification(Platform.OS === 'ios' ? notification.data.item ? notification.data.item : notification.data : notification.data) }
else { onOpenNotification({}) }
if (Platform.OS === 'ios') {
// (required) Called when a remote is received or opened, or local notification is opened
notification.finish(PushNotificationIOS.FetchResult.NoData)
}
},
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
sound: true,
},
// Should the initial notification be popped automatically
// default: true
popInitialNotification: true,
/**
* (optional) default: true
* - Specified if permissions (ios) and token (android and ios) will requested or not,
* - if not, you must call PushNotificationsHandler.requestPermissions() later
* - if you are not using remote notification or do not have Firebase installed, use this:
* requestPermissions: Platform.OS === 'ios'
*/
requestPermissions: true,
})
PushNotification.localNotification({
/* Android Only Properties */
...this.buildAndroidNotification(id, title, message, data, options),
/* iOS and Android properties */
...this.buildIOSNotification(id, title, message, data, options),
/* iOS and Android properties */
id: `${id}`,
title: title || "",
message: message || "",
playSound: options.playSound || false,
soundName: options.soundName || 'default',
userInteraction: true // BOOLEAN: If the notification was opened by the user from the notification area or not
});
为什么会这样?感谢您在这方面的帮助,谢谢!