我正在开展一个项目,我经常发布本地通知也会重复通知。 发出通知后,如果我删除了应用程序并再次安装(不打开它),我会收到所有旧通知。
答案 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;
}
请注意,它会取消所有通知。如果你想取消任何特定的通知,那么设置它的标签并使用标签取消此通知。