I am using the following code to receive custom data from a push notification and I get the following error:
Could not cast value of type \'__NSArrayM\' (
Read the error:
Could not cast value of expected type Array to offered type Dictionary
That means your JSON is an array, so
if let customDataString = pushManager.getCustomPushData(pushNotification) {
let data = customDataString.data(using: utf8)!
let jsonData = try? JSONSerialization.jsonObject(with: data) as! [[String:Any]]
...
You can omit the options
parameter, because .mutableContainers
is useless in Swift anyway.