evanshortiss / sns-mobile

Push notifications to Android, Kindle, and iOS devices easily using this module.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] How to send data (for example id) to mobile device?

alimustofa opened this issue · comments

Hi @evanshortiss, I am using sendMessage to send the notification, but I want to send some data to the mobile device (for example id). Please help me, thanks

@alimustofa, not sure I follow, do you mean you want to send a JSON object with extra data? If you take look here you can see that the String you pass is converted into the correct format for the device type.

If you want to include custom data you need to pass an Object instead of a String. The Object format for iOS is detailed here in the "Examples of JSON Payloads" scetion. Other systems have similar documentation.

Hope this is helpful.

@alimustofa here's an example based on the iOS link above.

sns.sendMessage(arn, {
    "aps" : {
        "alert" : {
            "title" : "Game Request",
            "body" : "Bob wants to play poker",
            "action-loc-key" : "PLAY"
        },
        "badge" : 5
    },
    "acme1" : "bar",
    "acme2" : [ "bang",  "whiz" ]
}, callback);

Okay thanks @evanshortiss for your fast response, I will try that example.

Sure @alimustofa, best of luck. Closing this. Comment again if you need to open it.