Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SNS Push Notifications with image using Node.js?

I am using Amazon SNS Mobile Push Notifications both for android and ios. I am quite successful with sending push notification with text and icon only. Now i am trying to send the notification with an image bottom. I searched every where but couldn't find a perfect docs to work on. Any suggestions please.

i installed this package using npm , i used this to send push notification. please refer this link. https://www.npmjs.com/package/sns-mobile

AWS_SNS_App.getUsers(function (err, allDevices) {
        if (err) {
            console.log(err, err.stack); // an error occurred
        } else {

            if (allDevices.length != 0) {
                var totalDevices = 0;
                for (var i = 0; i < allDevices.length; i++) {
                    totalDevices = totalDevices + 1;
                    AWS_SNS_App.sendMessage(allDevices[i].EndpointArn, message, function (err, messageId) {
                        if (err) {
                            console.log('An error occured sending message to device %s');

                            res.send(err);
                        } else {

                            //res.send('Successfully sent a message to device , MessageID was : ' + messageId);
                        }
                    });
                }
                if (totalDevices === allDevices.length) {
                    res.send('Successfully sent a message to all devices');
                }
            }
        }
    });

sendMessage(endpointArn, message, callback) Send a message to a user. The message parameter can be a String, or an Object with the formats below. The callback format is callback(err, messageId).

from docs it indicates to send a endpointArn,message and we will get a callback of any response. what i suppose to send an image along with the image, is that possible or any another way to do that.

thanks.

like image 220
Sukumar MS Avatar asked Aug 02 '17 05:08

Sukumar MS


1 Answers

Every image-containing push notification sent could contain a mediaReference that the app can later use to obtain content from a web service or from the apps bundled resources.

In any media case, the final resource link / bundle-resource-ref. can be composed within the app, (example) depending on other parameters within the push.

Remember that if the resource is not bundled you will have to download the image before displaying the notification (using it)

So the solution is in the client-side... Implement specific methods for each of your platforms (android & ios), perform the required operations (i repeat, different and specific to the platform) in order to display the push notification with the image.


NOTE : Tell me if you need references for building platform specific notifications with images. (and if so, what min sdk version you are using for each)

like image 159
EMX Avatar answered Oct 22 '22 04:10

EMX