如何在iOS中侦听通知被驳回的事件?

我列出了针对我的本地通知按下的操作,但有没有办法确定用户何时解除通知?

下面是我如何在我的AppDelegate中听取我的操作,但解雇不会触发这个:

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void) { var actionName: String? = nil if let identifier = identifier { switch identifier { case "snoozeAction": actionName = "snoozeActionTapped" break default: break } if let name = actionName { NSNotificationCenter.defaultCenter().postNotificationName(name, object: nil) } } completionHandler() } 

closures通知不会唤醒您的应用程序,因此无法捕获这些信息。

你应该试试这个:

  func application(application: UIApplication!, handleActionWithIdentifier identifier:String!, forLocalNotification notification:UILocalNotification!, completionHandler: (() -> Void)!){ if (identifier == "FIRST_ACTION"){ NSNotificationCenter.defaultCenter().postNotificationName("actionOnePressed", object: nil) }else if (identifier == "SECOND_ACTION"){ NSNotificationCenter.defaultCenter().postNotificationName("actionTwoPressed", object: nil) } completionHandler() }