I'm writing an app that sends a local push notification every fifteen minutes while a background timer is running via react-native-push-notification
. If notification n
isn't acted on by the user, when notification n+1
is pushed, I'd like to delete notification n
.
The things I've tried so far are to set popInitialNotification
to true
when running PushNotification.configure()
and setting ongoing
to true
when calling PushNotification.localNotification()
. I've also tried adding an id
when calling localNotification()
and then calling PushNotification.cancelLocalNotifications({id: myId})
, but the documentation explicitly says that cancelLocalNotifications()
only cancels scheduled notifications (and I'm pretty sure it means only future ones).
componentWillMount() { PushNotification.configure({ permissions: { alert: true, badge: true, sound: true }, popInitialNotification: true, });}doPushNotification() { if (AppState.currentState !== 'active') { PushNotification.localNotification({ vibration: 500, message: 'my message', ongoing: true, }); }}
Currently I'm only working on the Android version, but soon I'll work on the iOS version, so a general solution (or the solution for each) would be most helpful.
I'm not totally sold on react-native-push-notification
, either, if there's a better React Native library out there; I just haven't found one.
Edit
I figured it out for Android. Setting the id
when calling PushNotification.localNotification()
to the same value as the previous notification will overwrite the notification.
I'm still installing XCode on my Mac, so I can't test the current behavior on iOS just yet. However, the react-native-push-notification
readme says that id
is an Android-only option (as is ongoing
). I may still need help getting the iOS notifications to do what I want.