這是我的函數:爲什麼我在Swift中獲得多個UILocalNotifications?
func sendNotificationEvery() {
print("HEY!")
notification.alertBody = "Message here" // text that will be displayed in the notification
notification.fireDate = NSDate() // right now (when notification will be fired)
notification.soundName = UILocalNotificationDefaultSoundName // play default sound
notification.repeatInterval = NSCalendarUnit.Minute // this line defines the interval at which the notification will be repeated
notification.applicationIconBadgeNumber = 1
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
,我在這裏把它叫做:
override func viewWillDisappear(animated: Bool) {
sendNotificationEvery()
}
所以,問題是:當我關閉我的應用程序將其發送3-4通知,而不是1哪有我解決了這個問題?我想知道,爲什麼會發生?
你有沒有調整舊的通知? – Wain
使用'UIApplication.sharedApplication()。cancelAllLocalNotifications'來取消舊的通知。 – Sulthan
爲什麼你將重複間隔設置爲每分鐘? – Muneeba