Created
October 8, 2014 06:11
-
-
Save MehulATL/8c8bfa78f494d8f066c9 to your computer and use it in GitHub Desktop.
cordova push notifications
This file contains hidden or 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 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