我正在編寫一個應用程序並希望包含本地通知。我希望通知能夠在特定時間和每天重複發送。本地通知提供多次而不僅僅是一個
我把它編入我的應用程序,它確實通知用戶。然而,應用程序並不是每天在設定的時間通知一次,而是在設定的時間向用戶發送13+個通知。通知的數量每天都在增加。
如何解決此問題?我只想讓通知每天通知用戶一次。
這是我的代碼,我一直在使用。它是在應用程序委託的選項完成啓動時設置的。
let notificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Alert, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
let title: String = "Read Today's Pulse Habit!"
let calendar = NSCalendar.currentCalendar()
let calendarComponents = NSDateComponents()
calendarComponents.hour = 15
calendarComponents.minute = 30
calendarComponents.second = 0
calendar.timeZone = NSTimeZone.defaultTimeZone()
let dateToFire = calendar.dateFromComponents(calendarComponents)
let notification = UILocalNotification()
notification.alertBody = "\(title)"
notification.alertAction = "Read Now"
notification.fireDate = dateToFire
notification.alertTitle = "PULSE"
notification.repeatInterval = NSCalendarUnit.Day
notification.soundName = UILocalNotificationDefaultSoundName
notification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
UIApplication.sharedApplication().scheduleLocalNotification(notification)
我甚至嘗試拿出包含遞增圖標徽章號碼的行,並沒有任何區別。
你把這個實現放在哪裏?應用程序委託沒有關聯視圖,因此沒有viewDidLoad方法。 –
糟糕。我的意思是在應用程序委託中完成了與選項的完成啓動。 – Lindsay