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;