XCode 7, Swift 2. (don't even start on me about that, it's not my favorite set of constraints either)
So I'm sending data using node-apn (BIG thanks to those folks!). I'm using the (pushkit option) *.voip
topic and I got all that working. I can see the notification is received on my device (big shout out to libimobiledevice).
In composing the note on my server i'm doing
var note = new apn.Notification();
note.topic = 'mine.voip';
note.payload = {
message: 'text',
somethingElse: 'this other one '
payload: {
k1: v1,
k2: {
k3: v2
}
}
};
How am I supposed to get at my payload object? Following some (3rd party) pushkit examples (maybe it was 1? that showed like
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
let payloadDict = payload.dictionaryPayload["aps"] as? Dictionary<String, String>
let message = payloadDict?["alert"]
}
I tried to mimic it like
let myWeirdPayload = payload.dictionaryPayload["payload"] as? Dictionary<String, String>
or even
let myWeirdPayload = payload.dictionaryPayload["payload"] as? Dictionary<String, Any>
but those don't work (I get nil
).
How am I supposed to do this?
Let me try to make this clear by explaining the relation between
PKPushPayload
and itsNSDictionary
property with the data you are looking for.For the
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!)
you have thepayload
argument which is aPKPushPayload
.The data you are looking for are stored in the
_dictionaryPayload
which is aNSDictionary
and it is a property of thepayload
argument.So to access the data you can do: