【发布时间】:2016-09-05 14:34:27
【问题描述】:
所以这在 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”、“.automatic”和其他一些变体,但无法弄清楚。
【问题讨论】:
-
localNotification.timeZone = TimeZone.autoupdatingCurrent -
UILocalNotification 在 iOS10 中已弃用
-
成功了,谢谢。奇怪,我会想如果自动迁移会处理它那么简单。但是,如果您还说 UILocalNotification 已被弃用,我是否会遇到更大的问题?
-
暂时没问题,但以后您需要更改代码
标签: uilocalnotification swift3 nstimezone