react-native-android - 本地反应本机推送通知不起作用
问题描述
我在本地 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
});
为什么会这样?感谢您对此的帮助,谢谢!
解决方案
推荐阅读
- url - Keycloak Admin API 中“< string > array(csv)”模式的查询格式是什么?
- c# - 如何高效生成List
基于自定义模式? - node.js - 节点找不到绑定文件
- javascript - 如何让赛普拉斯包含返回布尔值而不是测试失败
- office-js - 清单中的语言覆盖不起作用
- angular - 当我在 Android 模拟器上运行构建时,Ionic App 在登录后崩溃
- macos - Mac vscode:使用 ctrl + 鼠标单击的多行
- javascript - 如何在firebase中从一个集合访问另一个集合
- jmeter - 当 jmeter 等待先前的响应发送新请求时,如何在 jmeter 中表示现实世界?
- python - 如何在 python 中模拟 Firestore where 函数?