Dima Rostopira Dima Rostopira - 3 months ago 14
iOS Question

UserInfo of UILocalNotification always nil

I am creating simple

UILocalNotification
, without scheduling, just from background with the following code:

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


I am printing
userInfo
inside

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


Until here everything is fine. But I need to dismiss some of notifications with the same id later on and create new ones. When I am trying to get them with
UIApplication.shared.scheduledLocalNotifications
all of them has
userInfo==nil
in iOS9 and
userInfo==["":""]
in iOS10 beta.

Answer

So, finally I find out, that scheduledLocalNotifications doesn't contain notifications, that already shown. The only way is to store them in array, or use NSKeyArchiver like said here.

Comments