Search code examples
uilocalnotificationswift3nstimezone

Swift 3 Local Notifications - Setting Automatic Timezone


So this worked flawlessly in Swift 2 but in Swift 3 it has problems:

func myNotifications () {
    let interval = 2.0
    var daysOut = 2.0
    let myArray =getArray()
    for i in 0..<myArray.count {
        let message = ("\(myArray[i])\n-\(myArray[i])")
        let localNotification = UILocalNotification()
        localNotification.fireDate = Date(timeIntervalSinceNow: (60*60*24*daysOut))
        localNotification.alertBody = message
        localNotification.timeZone = NSTimeZone.autoupdatingCurrent
        localNotification.category = "Message"
        UIApplication.shared.scheduleLocalNotification(localNotification)
        daysOut += interval
    }

    let arrayCount = Double(myArray.count)
    let lastNotif_Date = Date(timeIntervalSinceNow: (60*60*24*interval*(quoteCount+1)))
    userPref_NSDefault.set(lastNotif_Date, forKey: "notification_EndDate")
}

Specifically, this line no longer works which is a big deal because I have users in multiple timezones and I want to make sure this works:

  localNotification.timeZone = NSTimeZone.autoupdatingCurrent

I get the error message:

Type "NSTimeZone" has no member "autoUpdatingCurrent"

Any ideas? I tried "timeZone.automatic", ".automatic", and some other variations but haven't been able to figure it out.


Solution

    1. autoupdatingCurrent != autoupdatingCurrent
    2. NSTimeZone has been renamed to TimeZone