node-apn / node-apn

:calling: Apple Push Notification module for Node.js
MIT License
4.37k stars 680 forks source link

Custom payload not coming through #5

Closed tifroz closed 13 years ago

tifroz commented 13 years ago

Running bleeding-edge v1.1.0: the receiving end is missing the custom payload.

Sent from the server: var note = new apns.notification(); note.badge = 3; note.sound = "ping.aiff"; note.alert = "You have a new message"; note.payload = {'messageFrom': 'Caroline'}; note.device = myDevice; apnsConnection.sendNotification(note);

Received on iOS {"alert":"You have a new message","sound":"ping.aiff","badge":3}

(I double-checked my code in iOS...I hav a debug statement that spits out the notificationMessage object immediately after it is received so I have come to the conclusion that the sending component isn't sending everything

argon commented 13 years ago

I will need to investigate this further, but at first glance it would seem that whatever is getting printed out there is only the data within the 'aps' namespace of the notification. Can you provide some context of the code you are running on iOS so I can help.

tifroz commented 13 years ago

Thanks for the quick reply.

I created a gist https://gist.github.com/877914 with the objective-c class that handles all push-related things in my app

Background:  am using phonegap to run the app in webview, so the class essentially acts as a glue between native ios stuff and the javascript app. The relevant methods at the bottom are [setNotificationMessage] which stores the notification data in a global variable (notificationMessage), and [notificationReceived], which converts the data into JSON (using the JSON Framework library: http://stig.github.com/json-framework/ ) and invokes the app by call a delegate javascript method.

Note that the log statement from line 89 NSLog(@"setNotificationMessage:%@", notification); spits out exactly the snippet below which rules out the JSON conversion as a potential culprit

setNotificationMessage:{
    alert = "You have a new message";
    badge = 3;
    sound = "ping.aiff";
}
tifroz commented 13 years ago

Hum...I accidentally changed the status to 'closed' and apparently you can't re-open an issue unless you're a contributor on the repository. Can we consider this issue as open for all practical purposes ? :)

argon commented 13 years ago

Are you by any chance using the Urban Airship Push notification class?

tifroz commented 13 years ago

Yes and no - it's derived from the urbanairship plugin for phonegap, but it does not use urbanairship (plugs in directly into APN)

Sent from my iPhone

On Mar 20, 2011, at 2:27 AM, argonreply@reply.github.com wrote:

Are you by any chance using the Urban Airship Push notification class?

Reply to this email directly or view it on GitHub: https://github.com/argon/node-apn/issues/5#comment_894803

argon commented 13 years ago

Check your AppDelegate class because in the standard samples objectForKey:@"aps" is called on the notification dictionary in at least two places which will strip out the custom payload.

Try changing these lines to return the dictionary directly and see if that works.

tifroz commented 13 years ago

Bingo, you're absolutely right - I had completely forgotten about the very existence of these AppDelegate's methods. It worked like a charm after I implemented your suggestion.

Apologize for the trouble....can't say how much I appreciate you looking into it: Thank you !

argon commented 13 years ago

No problem, glad the library is of use to you.