我正在使用react-native-push-notification在React Native中计划和生成本地推送通知,并且我试图在收到任何计划的通知时清除以前收到的通知,或者在一段时间后自动删除当前收到的通知,但是我无法找到在iOS上实现它的任何方法。一种方法是使用库提供的timeoutAfter
属性,仅适用于android。对于iOS,如果我可以在接收本地通知时调用任何方法,但PushNotificationIOS.removeAllDeliveredNotifications()
在接收本地通知时不会触发,则可以使用onNotification()
。仅在接收或点击远程通知或点击本地通知时触发。还有其他方法或任何其他库可以实现此目的吗?这是我用于安排本地通知的代码:
PushNotification.localNotificationSchedule({
channelId: 'channelId',
id,
message: '...',
timeoutAfter: 10000,
soundName: 'default',
});
通知配置:
PushNotification.configure({
onRegister: function (token) {
console.log('TOKEN:', token);
},
onNotification: function (notification) {
console.log('NOTIFICATION:', notification);
},
onAction: function (notification) {
console.log('ACTION:', notification.action);
console.log('NOTIFICATION:', notification);
// process the action
},
onRegistrationError: function (err) {
console.error(err.message, err);
},
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: Platform.OS === OS.IOS,
});
答案 0 :(得分:0)
尽管它通常是一个坚固且维护良好的库,但我开始遇到react-native-push-notification
的一些相同问题。最终,我过渡到Notifee
:https://notifee.app/来生成/处理本地通知事件。它在弥合iOS和Android的根本差异方面做得很好,跨平台提供了相当统一的API。它似乎公开了取消API,尽管就我而言,我不需要实现那些。生产许可证需要付费,但这并不疯狂,在我看来,这绝对值得。另外,Notifee与react-native firebase
集成得很好,可以进行远程通知。