Ios 为什么可以';我不能取消重复的UILocalNotification吗?
再见,世界报。在我的Swift应用程序中,有一个Ios 为什么可以';我不能取消重复的UILocalNotification吗?,ios,iphone,swift,ipad,Ios,Iphone,Swift,Ipad,再见,世界报。在我的Swift应用程序中,有一个UILocalNotification计划在加载UIViewController一段时间后调用的方法中,它每小时重复一次(使用repeatInterval=.CalendarUnitHour)。我将此UILocalNotification实例存储在UIViewController的私有属性中,以便稍后取消它。当用户按下UIViewController中的按钮时,操作方法将触发取消通知实例,我通过该实例使用此代码(该代码也用于UIViewContro
UILocalNotification
计划在加载UIViewController
一段时间后调用的方法中,它每小时重复一次(使用repeatInterval=.CalendarUnitHour
)。我将此UILocalNotification
实例存储在UIViewController
的私有属性中,以便稍后取消它。当用户按下UIViewController
中的按钮时,操作方法将触发取消通知实例,我通过该实例使用此代码(该代码也用于UIViewController
的deinit
:
if let notification = notificationProperty {
UIApplication.sharedApplication().cancelLocalNotification(notification)
notificationProperty = nil
}
我在这里使用if-let语句来防止意外取消nil
UILocalNotification
。但即使在取消通知后,通知仍然每小时显示一次
那么为什么不能正确取消呢?谢谢!系统通知是您作为字段保留的通知的副本。您不能取消您保留的通知,因为它不是系统中的通知实例
您可以通过
cancelAllLocalNotifications
取消所有现有通知,或者通过scheduledLocalNotifications
属性迭代所有现有实例来查找要取消的通知。哦,这太令人惊讶了!感谢您的提示!但是每个重复的UILocalNotification
发布是否都算作一个单独的通知?或者重复的UILocalNotifications
作为一个组计算,所以当您取消它时,所有发布的通知都会被取消?