ios - 取消 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 上,即使在重新启动并重新安装 expo 后,我仍然收到相同的预定通知。
我试着打电话Notifications.cancelAllScheduledNotificationsAsync()
没有运气。
解决方案
当您的代码调用scheduleLocalNotificationAsync()
它时,它会向操作系统注册一个定期通知 - 删除代码是不够的。
我认为Notifications.cancelAllScheduledNotificationsAsync()
这是您正在寻找的:
推荐阅读
- c# - ASP.NET MVC 创建已存在错误的实体
- python - 从日期列表计算时间
- r - R studio 嵌套显示窗口任务栏字体大小
- polymer - 聚合物路由观察器 - 导致逻辑问题的多个实例
- android - 在 android 应用程序中使用授权 oauth 对用户进行身份验证。(我自己的 API)
- excel - 如何使用另一个单元格中公式中引用的范围/参数创建公式?
- r - 将列表转换为数据框
- django - 不能用 Python/Django 重新分配声明的变量
- excel - Excel 导出在 MVC 中不起作用。没有错误被抛出
- react-native - 反应本机文本输入错误