【问题标题】:UserInfo of UILocalNotification always nilUILocalNotification 的 UserInfo 始终为零
【发布时间】:2016-08-15 18:58:58
【问题描述】:

我正在创建简单的UILocalNotification,没有调度,只是从后台使用以下代码:

let n = UILocalNotification()
n.alertBody = "\(nam) \(wat)"
n.userInfo = ["id": id, "t":type.rawValue]
n.soundName = UILocalNotificationDefaultSoundName
n.category = "call_chat"
app.scheduleLocalNotification(n)

我在里面打印userInfo

func application(_ application: UIApplication, didReceive notification: UILocalNotification)

直到这里一切都很好。但是我需要稍后关闭一些具有相同 id 的通知并创建新通知。当我尝试使用UIApplication.shared.scheduledLocalNotifications 获取它们时,它们在iOS9 中都有userInfo==nil,在iOS10 beta 中具有userInfo==["":""]

【问题讨论】:

    标签: ios uilocalnotification swift3


    【解决方案1】:

    所以,最后我发现,scheduledLocalNotifications 不包含已显示的通知。唯一的方法是将它们存储在数组中,或者像 here 所说的那样使用NSKeyArchiver

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-02
      • 2012-01-16
      • 2020-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多