Skip to content

Instantly share code, notes, and snippets.

@ajoyoommen
Created August 22, 2015 06:53
Show Gist options
  • Save ajoyoommen/44353382695fff867ecf to your computer and use it in GitHub Desktop.
Save ajoyoommen/44353382695fff867ecf to your computer and use it in GitHub Desktop.
Initializing Cordova Project with PushPlugin
var Project = {};
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
receivedEvent: function(id) {
app.registerDevice();
},
registerDevice: function(){
if (window.cordova && window.cordova.platformId=='android'){
try{
var pushNotification = window.plugins.pushNotification;
pushNotification.register(
app.successPN,
app.errorPN,
{
"senderID": "727700427600",
"ecb": "Project.Notification"
}
);
}
catch (ex){
// window.alert('Error (message): ' + ex.message);
// window.alert('Error (stack): ' + ex.stack);
}
console.log("regID = " + localStorage['pioneer.device.regid']);
}
},
successPN: function (result){
// window.alert('PN Success: ' + result);
},
errorPN: function (result){
// window.alert('PN Error: ' + result);
}
};
app.initialize();
Project.Notification = function(e){
// Pioneer.alert(JSON.stringify(e), 'alert');
switch( e.event )
{
case 'registered':
// process reg id
break;
case 'message':
// print message
break;
case 'error':
// window.alert("Notification error: " + e.msg);
break;
default:
// window.alert("Notification - Unknown event");
break;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment