【问题标题】:Swift 3 Local Notifications - Setting Automatic TimezoneSwift 3 本地通知 - 设置自动时区
【发布时间】: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


【解决方案1】:
  1. autoupdatingCurrent != autoupdatingCurrent
  2. NSTimeZone 已重命名为 TimeZone

【讨论】:

  • 是的,但他的错误信息显示为大写 U,他有一个错字。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 2017-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多