How to get userInfo JSON Value inside didReceiveRemoteNotification
As mentioned in the comments, there is no key test
in the APNS payload.
If the value for key message
is guaranteed to be sent always you can easily unwrap the value
let msg = userInfo["message"] as! String
print(msg)
otherwise use optional binding
if let msg = userInfo["message"] as? String {
print(msg)
}
To get the alert
dictionary from the aps
key and print for example the body
string use
if let aps = userInfo["aps"] as? [String:Any],
let alertDict = aps["alert"] as? [String:String] {
print("body :", alertDict["body"]!)
}