I tried scheduling local notifications using expo (react native) and something very strange is happening.
This is the code I wrote:
const localNotification = {
title: 'test',
body: 'test body',
ios: {
sound: true
}
};
let t = new Date();
t.setSeconds(t.getSeconds() + 10);
const schedulingOptions = {
time: t, // (date or number) — A Date object representing when to fire the notification or a number in Unix epoch time. Example: (new Date()).getTime() + 1000 is one second from now.
repeat: 'minute'
};
Notifications.scheduleLocalNotificationAsync(localNotification, schedulingOptions);
Then I started to receive the same notification every time the app is in background.
I removed that piece of code to use Notifications.presentLocalNotificationAsync()
instead and I expected the previous notification to stop appearing as Notifications.scheduleLocalNotificationAsync()
is never called anywhere in the whole app.
On Android I rebooted the phone and the notification doesn't appear anymore, but on iOS even after rebooting and reinstalling expo I keep getting the same scheduled notification.
I tried calling Notifications.cancelAllScheduledNotificationsAsync()
with no luck.
When your code called scheduleLocalNotificationAsync()
it registered a recurring notification with the OS - removing the code isn't enough.
I think Notifications.cancelAllScheduledNotificationsAsync()
is what you're looking for:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.