这是我的函数:为什么我在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