0
votes

I am attempting to retrieve the custom data sent in a push notification.

The custom data is :

[{"test":"01"}]

The pushNotification is recieved as:

[AnyHashable("aps"): { alert = "Hello World!"; sound = default;}, AnyHashable("u"): [{"test":"01"}] , AnyHashable("p"):2Q]

And my push accepted is as follows:

 func onPushAccepted(_ pushManager: PushNotificationManager!, withNotification pushNotification: [AnyHashable : Any]!, onStart: Bool) {
        print("Push notification accepted: \(pushNotification!)")

        if let aps = pushNotification["aps"] as? [String:Any] {
            let customData = aps["u"] as! String

            print("json String:\(customData)")
        }

When I run the code it crashes on line:

let customData = aps["u"] as! String

Any help much appreciated!

1

1 Answers

0
votes

First of all excuse me if I am not correct but you are picking the wrong key.

if let aps = pushNotification["aps"] as? [String:Any] 

should be

if let data = pushNotification["u"] as? [String:Any]

and then you can get the value for test like this

data["test"]

hope I am correct and this will help you