Reputation: 691
I'm doing an alarm application with repeat interval. My problem is that even if the user clicks the local notification, returns to the app, and then goes back to the home screen of the phone the UILocalNotification
stills fire every minute. I'm aware of [[UIApplication sharedApplication] cancelAllLocalNotifications];
and I put it in the my viewDidLoad
method. Any advice how I can fix this?
Upvotes: 1
Views: 185
Reputation: 10602
Putting it in viewDidLoad
is good for some circumstances just not yours. Think about when viewDidLoad
is called:
Called after the controller's view is loaded into memory.
So in other words, the next time it gets called is after your little ARC
friend deallocates it from memory. So, yes, eventually cancelAllLocalNotifications
will get called again, just not when a user puts the app in the background and then returns it to foreground, because its still has a home in memory; it will be called next time that particular view gets loaded into the memory.
Additionally, that probably is not good logic, because that will happen for every user, even if they didn't want to cancel the repeats.
Ultimately, you will have to create additional logic to decipher which users have, say, hit 'snooze' or 'cancel' with whatever resource works for you and your project. Personally, I would guide you towards using a category based notification, that way you cancel it as needed, instead of 'just in case'. See here how to set those up.
Upvotes: 1