[英]React Native - Clear previous push notifications on receiving local push notification
我正在使用react-native-push-notification来安排和生成 React Native 中的本地推送通知,我正在尝试清除以前收到的收到任何计划通知的通知或在一段时间后自动删除当前收到的通知,但我找不到在 iOS 上实现它的任何方式。 一种方法是使用仅适用于 android 的库提供的timeoutAfter
属性。 对于 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,
});
虽然它通常是一个可靠且维护良好的库,但我开始遇到一些与react-native-push-notification
相同的问题。 最终,我Notifee
: https : Notifee
来生成/处理本地通知事件。 它在弥合 iOS 和 Android 之间的潜在差异方面做得相当不错,提供了跨平台非常统一的 API。 它似乎公开了取消 API,但就我而言,我不需要实现这些 API。 生产许可证需要付费,但这并不疯狂,在我的情况下绝对值得。 此外,Notifee 与用于远程通知的react-native firebase
firebase 很好地集成在一起,fwiw。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.