Swift 3本地通知 - 设置自动时区

时间:2016-09-05 14:34:27

标签: uilocalnotification swift3 nstimezone

所以这在Swift 2中完美无缺,但在Swift 3中它有问题:

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")
}

具体来说,这条线不再有效,这是一个大问题,因为我有多个时区的用户,我想确保它有效:

  localNotification.timeZone = NSTimeZone.autoupdatingCurrent

我收到错误消息:

  

类型“NSTimeZone”没有成员“autoUpdatingCurrent”

有什么想法吗?我尝试过“timeZone.automatic”,“。auto”和其他一些变种,但还是没能弄明白。

1 个答案:

答案 0 :(得分:1)

  1. autoupdatingCurrent!= autoupdatingCurrent
  2. NSTimeZone已重命名为TimeZone