UILocalNotification 的 UserInfo 始终为 nil

UserInfo of UILocalNotification always nil

我正在创建简单的 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==["":""]

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

那样使用 NSKeyArchiver