My app keeps giving UILocalNotifications even though there are none in the code

49 views Asked by At

I put some UILocalNotifications in my code as a way of telling me when I had crossed over certain geographic barriers I programmed into my app. However, I've since taken these notifications out. I have even typed in "UILocalNotification" into spotlight on my mac and seen that none of my project's files contain this word. Why, then, am I still getting these notifications? I've deleted the app from my phone, then reinstalled it, and I'm still getting them.

1

There are 1 answers

10
nburk On BEST ANSWER

UILocalNotifications are scheduled by iOS itself (the actual operation system), i.e. once your app schedules the notification, it sits in the OS and waits to fire (or to be cancelled). This is why deleting the app doesn't help anything. The notification doesn't sit in the app, but in the system.

You can solve this issue by calling once in your AppDelegate (e.g. in didFinishLaunching):

[[UIApplication sharedApplication] cancelAllLocalNotifications];

Once you called this line, all the notifications that have ever been scheduled by your app will be cancelled.

If you're just curios how many notifications are currently scheduled, you can check that be retrieving all the notifications using

NSArray *scheduledNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];