UILocalNotification 我的警报每分钟触发一次 swift 2.0
UILocalNotification my alert fires every minute swift 2.0
我需要你的帮助。我为 localNotifications 编写代码。
func scheduleNotification() {
// Schedule the notification
let localNotification = UILocalNotification()
localNotification.fireDate = dueDate
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.alertBody = text
localNotification.soundName = UILocalNotificationDefaultSoundName
// at first start I write this line [1]
// localNotification.repeatInterval = NSCalendarUnit.Second
localNotification.repeatInterval = NSCalendarUnit.Weekday
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
在这个区域 [1] 中,我首先使用 NScalendarUnit.Second 编写该代码并启动我的应用程序。警报触发正常,但它不会停止并每分钟触发一次。之后,我从 iPhone 中删除了我的应用程序,并在工作日行中粘贴了新的代码行。我启动应用程序并添加新警报工作正常,但我在第一次启动时创建的第一个警报在触发第二个警报后每分钟继续触发。
您仍然需要取消旧的重复通知。
您可以在适当过滤后使用 scheduledLocalNotification
, you can then cancel it with cancelLocalNotification
检索当前计划通知的列表。
或者如果你没有任何其他通知,你可以直接使用cancelAllLocalNotifications
。
我需要你的帮助。我为 localNotifications 编写代码。
func scheduleNotification() {
// Schedule the notification
let localNotification = UILocalNotification()
localNotification.fireDate = dueDate
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.alertBody = text
localNotification.soundName = UILocalNotificationDefaultSoundName
// at first start I write this line [1]
// localNotification.repeatInterval = NSCalendarUnit.Second
localNotification.repeatInterval = NSCalendarUnit.Weekday
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
在这个区域 [1] 中,我首先使用 NScalendarUnit.Second 编写该代码并启动我的应用程序。警报触发正常,但它不会停止并每分钟触发一次。之后,我从 iPhone 中删除了我的应用程序,并在工作日行中粘贴了新的代码行。我启动应用程序并添加新警报工作正常,但我在第一次启动时创建的第一个警报在触发第二个警报后每分钟继续触发。
您仍然需要取消旧的重复通知。
您可以在适当过滤后使用 scheduledLocalNotification
, you can then cancel it with cancelLocalNotification
检索当前计划通知的列表。
或者如果你没有任何其他通知,你可以直接使用cancelAllLocalNotifications
。