Swift 3 本地通知 - 设置自动时区
Swift 3 Local Notifications - Setting Automatic Timezone
所以这在 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
我收到错误消息:
Type "NSTimeZone" has no member "autoUpdatingCurrent"
有什么想法吗?我尝试了 "timeZone.automatic"、“.automatic”和其他一些变体,但一直无法弄清楚。
autoupdatingCurrent
!= autoupdatingCurrent
NSTimeZone
已重命名为 TimeZone
所以这在 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
我收到错误消息:
Type "NSTimeZone" has no member "autoUpdatingCurrent"
有什么想法吗?我尝试了 "timeZone.automatic"、“.automatic”和其他一些变体,但一直无法弄清楚。
autoupdatingCurrent
!=autoupdatingCurrent
NSTimeZone
已重命名为TimeZone