i m using Ionic platform to create a mobile app and need a help about this situation. I can take regId with this code and then can send notification.
But when i send a notification about a shop from my app, how can i open that shop's page when click notification that i get ?
var pushNotification;
function onDeviceReady() {
document.addEventListener("backbutton", function (e) {}, false);
var pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android' || device.platform ==
'amazon-fireos') {
pushNotification.register(successHandler, errorHandler, {
"senderID": "788xxxxxxxx",
"ecb": "onNotificationGCM"
});
}
}
// handle APNS notifications for iOS
function onNotificationAPN(e) {
// alert('apn');
if (e.alert) {
// showing an alert also requires the org.apache.cordova.dialogs plugin
navigator.notification.alert(e.alert);
}
if (e.sound) {
// playing a sound also requires the org.apache.cordova.media plugin
var snd = new Media(e.sound);
snd.play();
}
if (e.badge) {
pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge);
}
}
// handle GCM notifications for Android
//function onNotification(e) {
onNotificationGCM = function (e) {
// alert('onnoti');
switch (e.event) {
case 'registered':
if (e.regid.length > 0) {
// alert('f');
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
alert("regID = " + e.regid);
$rootScope.regidx = e.regid;
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if (e.foreground) {
// on Android soundname is outside the payload.
// On Amazon FireOS all custom attributes are contained within payload
var soundfile = e.soundname || e.payload.sound;
// if the notification contains a soundname, play it.
// playing a sound also requires the org.apache.cordova.media plugin
var my_media = new Media("/android_asset/www/" + soundfile);
my_media.play();
}
break;
case 'error':
break;
default:
break;
}
}
function tokenHandler(result) {
alert('device token = ' + result);
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
}
function successHandler(result) {
alert('Callback Success! Result = ' + result)
}
function errorHandler(error) {
alert(error);
}