Skip to content

Instantly share code, notes, and snippets.

@MehulATL
Created October 8, 2014 06:11
Show Gist options
  • Save MehulATL/8c8bfa78f494d8f066c9 to your computer and use it in GitHub Desktop.
Save MehulATL/8c8bfa78f494d8f066c9 to your computer and use it in GitHub Desktop.
cordova push notifications
var pushNotification = window.plugins.pushNotification;
window.onNotificationAPN = onNotificationAPN;
pushNotification.register(
tokenHandler,
errorHandler, {
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
}
);
function successHandler(result) {
console.log('success result ' + result);
// API call to store token on your DB
}
function errorHandler(error) {
console.log('error result ' + error);
}
function onNotificationAPN(e) {
alert('Inside the onNotificationAPN callback!');
if ( e.alert ) {
navigator.notification.alert(e.alert);
}
if ( e.sound ) {
var snd = new Media(e.sound);
snd.play();
}
if ( e.badge ) {
pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, e.badge);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment