Created
March 24, 2016 16:42
-
-
Save sethannabel/68ae83a338ad4bc1eb6e to your computer and use it in GitHub Desktop.
phonegap-plugin-push sample code
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
if (window.cordova) { | |
var devicePlatform = device.platform; | |
var uuid = device.uuid; | |
var deviceToken = null; | |
var push = PushNotification.init({ | |
"android": { | |
"senderID": "xxxxxxxxxxx" | |
}, | |
ios: { | |
alert: "true", | |
badge: "true", | |
sound: "true" | |
} | |
}); | |
push.on('registration', function (data) { | |
console.log("--- My App Push Registration " + data.registrationId); | |
}); | |
push.unregister(function () { | |
console.log('--- My App Push unregister success'); | |
}, function () { | |
console.log('--- My App Push unregister error'); | |
}); | |
push.setApplicationIconBadgeNumber(function () { | |
console.log('--- My App Push setApplicationIconBadgeNumber success'); | |
}, function () { | |
console.log('--- My AppPush setApplicationIconBadgeNumber error'); | |
}, 0); | |
push.getApplicationIconBadgeNumber(function (n) { | |
console.log('--- My App Push getApplicationIconBadgeNumber success', n); | |
}, function () { | |
console.log('--- My App Push getApplicationIconBadgeNumber error'); | |
}); | |
push.on('notification', function (data) { | |
console.log(data.message); | |
console.log(data.title); | |
console.log(data.count); | |
console.log(data.sound); | |
console.log(data.image); | |
console.log(data.additionalData); | |
console.log(data.additionalData.foreground); | |
console.log(data.additionalData.coldstart); | |
}); | |
push.finish(function () { | |
console.log('--- My App Push finish success'); | |
}, function () { | |
console.log('Push finish error'); | |
}); | |
push.on('error', function (e) { | |
console.log("--- My App Push Error Event " + e); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment