Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么可以';我不能取消重复的UILocalNotification吗?_Ios_Iphone_Swift_Ipad - Fatal编程技术网

Ios 为什么可以';我不能取消重复的UILocalNotification吗?

Ios 为什么可以';我不能取消重复的UILocalNotification吗?,ios,iphone,swift,ipad,Ios,Iphone,Swift,Ipad,再见,世界报。在我的Swift应用程序中,有一个UILocalNotification计划在加载UIViewController一段时间后调用的方法中,它每小时重复一次(使用repeatInterval=.CalendarUnitHour)。我将此UILocalNotification实例存储在UIViewController的私有属性中,以便稍后取消它。当用户按下UIViewController中的按钮时,操作方法将触发取消通知实例,我通过该实例使用此代码(该代码也用于UIViewContro

再见,世界报。在我的Swift应用程序中,有一个
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
作为一个组计算,所以当您取消它时,所有发布的通知都会被取消?