Skip to content

Instantly share code, notes, and snippets.

@ericholscher
Created August 9, 2012 17:18
Show Gist options
  • Save ericholscher/3306077 to your computer and use it in GitHub Desktop.
Save ericholscher/3306077 to your computer and use it in GitHub Desktop.
Urban Airship Phonegap Example
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) {
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) {
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) {
console.log("The user formerly known as " + alias)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment