iOS 9.2.1,取消通知不起作用

iOS 9.2.1, cancel notifcation not working

我正在开发一个安排了本地通知的应用程序。 我无法使用代码取消预定的通知:

UIApplication *app=[UIApplication sharedApplication];  
[app cancelLocalNotification:notification];

该代码在以前的 iOS 版本中运行良好,但在 iOS 9.2.1 更新中停止运行。

谁能帮我解决这个问题?

iOS 9.2.1 中存在错误,因此 cancelLocalNotification 方法有时不起作用。 使用 cancelLocalAllNotifications 并相应地更新您的逻辑。 这应该有效。

在调度时将本地通知对象保留在 NSUSerDefault 中,即使您的设备重新启动,您也可以从 NSUSerDefault 中检索本地通知对象。那么在您可以轻松地在 cancelLocalNotification(localNotificationObject) 中传递该对象并将其删除之后。