iOS application: how to clear notifications?

http://stackoverflow.com/questions/8682051/ios-application-how-to-clear-notifications

 

Just to expand on pcperini's answer. As he mentions you will need to add the following code to yourapplication:didFinishLaunchingWithOptions: method;

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];

You Also need to increment then decrement the badge in your application:didReceiveRemoteNotification: method if you are trying to clear the message from the message centre so that when a user enters you app from pressing a notification the message centre will also clear, ie;

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
posted @ 2016-05-18 11:24  willbin  阅读(247)  评论(0编辑  收藏  举报