Created
August 22, 2015 06:53
-
-
Save ajoyoommen/44353382695fff867ecf to your computer and use it in GitHub Desktop.
Initializing Cordova Project with PushPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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