Skip to content

Instantly share code, notes, and snippets.

@edwardsharp
Created October 9, 2012 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardsharp/3856633 to your computer and use it in GitHub Desktop.
Save edwardsharp/3856633 to your computer and use it in GitHub Desktop.
#urbanairship
document.addEventListener("deviceready", function() {
// BEGIN UA PUSH NOTIFICATION INIT
push = window.pushNotification;
// Callback for when a device has registered with Urban Airship.
// https://docs.urbanairship.com/display/DOCS/Server%3A+Android+Push+API#ServerAndroidPushAPI-Registration
push.registerEvent('registration', function (id) {
console.log("Registered with ID: " + id)
});
// Callback for when the app is running, and recieves a push.
push.registerEvent('push', function (push) {
if (DEBUG) { console.log("Got push: " + push.message); }
});
// Set tags on a device, that you can push to
// https://docs.urbanairship.com/display/DOCS/Server%3A+Tag+API
/*
push.setTags(["loves_cats", "shops_for_games"], function () {
push.getTags(function (obj) {
obj.tags.forEach(function (tag) {
if (DEBUG) { console.log("Tag: " + tag); }
});
});
});
// Set an alias, this lets you tie a device to a user in your system
// https://docs.urbanairship.com/display/DOCS/Server%3A+iOS+Push+API#ServeriOSPushAPI-Alias
push.setAlias(["awesomeuser22"], function () {
push.getAlias(function (alias) {
if (DEBUG) { console.log("The user formerly known as " + alias); }
});
});
*/
// Check if push is enabled
push.isPushEnabled(function (enabled) {
if (enabled) {
if (DEBUG) { console.log("Push is enabled! Fire away!"); }
}
})
if (DEBUG) { console.log("-----window.pushNotification.registrationCallback: " + window.pushNotification.registrationCallback); }
// END UA PUSH NOTIFICATION INIT
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment