删除代码后触发本地通知 [英] Local notification fired after deleting code

查看:20
本文介绍了删除代码后触发本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 UILocalNotification 时遇到了一个奇怪的问题.我在每晚 11:59 安排本地通知.现在,我已经从我的项目中删除了该代码,但我仍然每天晚上 11:59 收到该本地通知.我尝试从设备中删除构建,更改设备并清理派生数据.

I am facing a weird problem with UILocalNotifiation. I was scheduling a local notification at 11:59 every night. Now, I have deleted that code from my project but I am still receiving that local notification every night at 11:59. I have tried to remove build from device, change device and clean derived data.

推荐答案

这实际上是标准的 iOS 行为,因为您在 iOS(实际操作系统)上安排通知.这意味着,一旦你安排了一个 UILocalNotification,它就会一直驻留在操作系统中,直到它被触发或被手动取消.

That's actually standard iOS behaviour, since you schedule the notifications on iOS (the actual operating system). This means, that once you scheduled a UILocalNotification, it will sit in the operating system until it either fires or gets cancelled manually.

因此,对于您的情况,听起来您最初安排了许多通知,现在这些通知都在操作系统中等待触发.当您更改代码或删除应用时,它们不会消失,只有在您删除它们或它们被解雇时它们才会消失.

So, for your case, it sounds like you initially scheduled a number of notifications, these are now all sitting in the operating system waiting to fire. They won't go away when you change your code or delete the app, they will only go away f you either delete them or when they get fired.

为了确保您不会收到过去安排的任何通知,您可以使用以下方法删除它们:

In order to make sure, you don't receive any notifications that have been scheduled in the past, you can delete them using:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

您还可以获取应用当前安排的所有通知并单独取消它们:

You can also get all notifications that are currently scheduled by your app and cancel them individually:

NSArray *activeNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
for (UILocalNotification *notification in activeNotifications) {
   [[UIApplication sharedApplication] cancelNotification:notification];
}

这篇关于删除代码后触发本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆