Ravi Gautam
Ravi Gautam

Reputation: 978

Local notification fired after deleting code

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.

Upvotes: 3

Views: 454

Answers (1)

nburk
nburk

Reputation: 22751

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];
}

Upvotes: 9

Related Questions