I saw that and have part of this in my application. I want to be able to handle the callback being sent from the server. This is not shown in here.
Here is a screen shot of the type of notification i am getting in my app
I am want to be able to handle the ‘Email Guests’ and ‘Snooze’ in my app.
Here is the message that I am pushing from my server:
var message = new gcm.Message(); //create a new message
message.addData(‘title’, ‘Test Push with Action’);
message.addData(‘message’, ‘Follow me?’);
message.addData(‘sound’, ‘notification’);
message.addData(‘actions’, [{
“icon”: “emailGuests”,
“title”: “FOLLOW”,
“callback”: “follow”
}, {
“icon”: “snooze”,
“title”: “DISMISS”,
“callback”: “dismiss”
}, ]);
message.addData(“image”, “https://dl.dropboxusercontent.com/u/887989/antshot.png”);
message.addData(“style”, “inbox”);
message.addData(“summaryText”, “There are %n% notifications”);
message.addData(“content-available”, “1”);
And this is what I have at the app side but don’t know how to intercept the action pressed to behave accordingly
Console logs on device when message is received:
Received Something !!!
Data …
image https://dl.dropboxusercontent.com/u/887989/antshot.png
sound notification
title Test Push with Action
message Follow me?
additionalData [object Object]
Additional data [object Object]
content-available 1
summaryText There are %n% notifications
actions [object Object],[object Object]
style inbox
collapse_key do_not_collapse
foreground false
cordova.js:310 Error in Success callbackId: PushNotification1990689049 : TypeError: Cannot read property ‘apply’ of undefined
cordova.js:312 Uncaught TypeError: Cannot read property ‘apply’ of undefined
cordova.js:310 Error in Success callbackId: PushNotification1990689049 : TypeError: Cannot read property ‘apply’ of undefined
App Side Code:
(how to get the action and handle???)
push.on(‘notification’, function(data) {
console.log(“Received Something !!!”)
console.log(“Data …”);
Object.keys(data).forEach(function (key) { console.log(key + " " + data[key]); })
// alert(data.title + " Message: " + data.message);
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
if (data.additionalData) {
console.log("Additional data " + data.additionalData);
Object.keys(data.additionalData).forEach(function (key) { console.log(key + " " + data.additionalData[key]); })
} else {
console.log('no additional data');
}
});
push.on('error', function(e) {
console.log(e.message);
});