Search code examples
iosuilocalnotificationswift3

Schedule notification every day in exact time


I'm trying to show notification everyday in exact time, but it's firing sometimes few times for an hour, or not firing at all 0_o

let not = UILocalNotification()
not.soundName = UILocalNotificationDefaultSoundName
not.alertBody = "Time to stop drink!"
not.fireDate = Calendar.current.date(bySettingHour: HOUR, minute: MINUTE, second: 0, of: Date(), options: Calendar.Options())
not.repeatInterval = Calendar.Unit.day
UIApplication.shared().scheduleLocalNotification(not)

Solution

  • Thanks to @LeoDabus, I added just one line not.timeZone = TimeZone.default and it's working now