本地通知的重复间隔不能正常工作 (Swift)

Repeat Interval is not working correctly for local notifications (Swift)

无论我将其设置为什么,我的重复间隔大约每 60 秒关闭一次。这是我的代码。此外,只要它每 60 秒重复一次,就会同时发出两个通知。为了阐明我想要做什么,我希望我的通知每周发出一次,以提醒我的 sprite kit 游戏的玩家回来玩。

    let localNotification = UILocalNotification() // Creating an instance of the notification.
    localNotification.alertTitle = "Title"
    localNotification.alertBody = "Body"
    localNotification.alertAction = "Launch"
    localNotification.repeatInterval = .Hour
    localNotification.timeZone = NSTimeZone.defaultTimeZone()
    localNotification.soundName = UILocalNotificationDefaultSoundName // Use the default notification tone/ specify a file in the application bundle
    localNotification.applicationIconBadgeNumber = 1 // Badge number to set on the application Icon.
    localNotification.fireDate = NSDate(timeIntervalSinceNow: 5)        
    UIApplication.sharedApplication().scheduleLocalNotification(localNotification) // Scheduling the notification.  

发生的事情是您尝试安排一个无效的 repeatInterval 单元。最小重复间隔单位是.分钟。那么当您尝试一个有效的单元时发生了什么,但您仍然收到默认设置为每分钟重复的第一个计划通知。

只需取消所有以前的日程通知并安排新通知即可。

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/cancelAllLocalNotifications