Remove Push Notifications from Notification Center in iOS Development

By | 2013 年 1 月 22 日

If the notification is local, it’s easy by
如果是本地通知,下面的代码就解决了。

[[UIApplication sharedApplication] cancelAllLocalNotifications];

But if the notifications come from the push notification, this does’t work.
但是如果是来自于推送的话,这不管用。
After search and try, only the third method in a blog works, although it’s weird.
搜了很久发现有一个办法可以解决,虽然这个办法非常怪异。

UIApplication* application = [UIApplication sharedApplication];
NSArray* scheduledNotifications = [NSArray arrayWithArray:application.scheduledLocalNotifications];
application.scheduledLocalNotifications = scheduledNotifications;

<br>
Reference
http://josh-asch.net/2012/02/29/ios-development-remove-old-notifications-from-notification-center/

发表评论

电子邮件地址不会被公开。 必填项已用*标注