Piyush
Piyush

Reputation: 1234

How to remove local notification after fired notification in IOS

I am working on a project where I fire a local notification frequently also repeat notification. After fired notification, if I delete the application and install it again (without opening it), I get all the old notifications.

Upvotes: 3

Views: 2094

Answers (3)

rakesh_chovatiya
rakesh_chovatiya

Reputation: 48

 - (void)applicationWillTerminate:(UIApplication *)application
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}
 *and then set remaining all notification in*
 - (void)applicationDidBecomeActive:(UIApplication *)application
{
    UILocalNotification *notif = [[UILocalNotification alloc]init];
[[UIApplication sharedApplication] scheduleLocalNotification:notif];

}

Upvotes: 1

Renish Dadhaniya
Renish Dadhaniya

Reputation: 10752

put your code in App did finish launching method.so, when app launch then it's cancel the all notification.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//cancel All notification when app is launch
 [[UIApplication sharedApplication] cancelAllLocalNotifications];

    return YES;
}

Pls note that it cancel the all notification. if u want to cancel any particular notification then set it's tag and using tag cancel this notification.

Upvotes: 0

nerowolfe
nerowolfe

Reputation: 4817

Try this:

-(void)clearNotifications
{
 [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1];
 [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
 [[UIApplication sharedApplication] cancelAllLocalNotifications];
}

Upvotes: 1

Related Questions