[英]Cancel all expo local scheduled notifications on iOS
我尝试使用 expo (react native) 安排本地通知,但发生了一些非常奇怪的事情。
这是我写的代码:
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);
然后每次应用程序在后台时我都开始收到相同的通知。
我删除了那段代码以使用Notifications.presentLocalNotificationAsync()
代替,我希望之前的通知停止出现,因为Notifications.scheduleLocalNotificationAsync()
在整个应用程序中的任何地方都不会被调用。
在 Android 上,我重新启动了手机,通知不再出现,但在 iOS 上,即使在重新启动并重新安装世博会后,我仍然收到相同的预定通知。
我尝试调用Notifications.cancelAllScheduledNotificationsAsync()
,但没有成功。
当您的代码调用scheduleLocalNotificationAsync()
它向操作系统注册了一个重复通知 - 删除代码是不够的。
我认为Notifications.cancelAllScheduledNotificationsAsync()
是你正在寻找的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.