Question

I'm developping an app that sends tips to users every five minutes through UILocalNotifications. The problem is that if you don't use your phone for a while, the notifications pile up and when you unlock the phone, you have to dismiss them one after the other, which can become quite annoying if you haven't used the phone for quite a while. Clicking the action button on the Alert sends you back to the application but even then, you still have to go through all the notifications.

Is there any means of dismissing all the notifications that have already been fired with a single click ?

Thanks for your help.

Miky Mike

Was it helpful?

Solution

Well, actually, I realize I made a mistake.

In order to cancel all the UIlocalNotifications at one, I just have to create this simple method : one line of code is enough :

 - (void)application:(UIApplication *)app didReceiveLocalNotification :(UILocalNotification *)notification {

[[UIApplication sharedApplication] cancelAllLocalNotifications];
}

and there you are. Thanks anyway.

OTHER TIPS

Before scheduling the next alarm you better to cancel all the previous notifications and then set the new one,

UIApplication* app = [UIApplication sharedApplication]; 
NSArray* oldNotifications = [app scheduledLocalNotifications];
// Clear out the old notification before scheduling a new one. 
if ([oldNotifications count] > 0)
   [app cancelAllLocalNotifications];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top