如何在IOS中触发通知后删除本地通知

时间:2014-05-08 11:19:09

标签: ios

我正在开展一个项目,我经常发布本地通知也会重复通知。 发出通知后,如果我删除了应用程序并再次安装(不打开它),我会收到所有旧通知。

3 个答案:

答案 0 :(得分:1)

试试这个:

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

答案 1 :(得分:1)

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

}

答案 2 :(得分:0)

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

请注意,它会取消所有通知。如果你想取消任何特定的通知,那么设置它的标签并使用标签取消此通知。