Skip to content

Instantly share code, notes, and snippets.

@jonalter
Created March 12, 2013 21:03
Show Gist options
  • Save jonalter/5147010 to your computer and use it in GitHub Desktop.
Save jonalter/5147010 to your computer and use it in GitHub Desktop.
UrbanAirship example for the ti.newsstand module
////////////////////////////////////////////////////////
// Urban Airship
// Uncomment the code below to use Urban Airship
////////////////////////////////////////////////////////
/**
var UrbanAirship = require('ti.urbanairship');
UrbanAirship.tags = [ 'testingtesting', 'appcelerator', 'my-tags' ];
UrbanAirship.alias = 'testDevice';
UrbanAirship.autoBadge = true;
UrbanAirship.autoResetBadge = true;
function eventCallback(e) {
// Pass the notification to the module
UrbanAirship.handleNotification(e.data);
Ti.API.info('Push message received');
Ti.API.info(' Message: ' + e.data.alert);
Ti.API.info(' Payload: ' + e.data.aps);
Ti.API.info(' Content-Available: ' + e.data['content-available']);
if (e.data['content-available'] === 1) {
var name = issues[0].name;
var content = issues[0].content;
Ti.API.info('Downloading asset for issue: '+name+' from URL: '+content);
var issue = Newsstand.getIssue({
name: name
});
if (!issue) {
// if issue is not found then add it
issue = Newsstand.addIssue({
name: name,
date: new Date()
});
}
issue.downloadAsset({
url: content,
userInfo: {
id: 9999,
name: 'TESTBACKGROUND'
}
});
}
}
function eventSuccess(e) {
// *MUST* pass the received token to the module
UrbanAirship.registerDevice(e.deviceToken);
Ti.API.info('Received device token: ' + e.deviceToken);
}
function eventError(e) {
Ti.API.info('Error:' + e.error);
var alert = Ti.UI.createAlertDialog({
title: 'Error',
message: e.error
});
alert.show();
}
Ti.Network.registerForPushNotifications({
types:[
// Ti.Network.NOTIFICATION_TYPE_BADGE,
// Ti.Network.NOTIFICATION_TYPE_ALERT,
// Ti.Network.NOTIFICATION_TYPE_SOUND
Ti.Network.NOTIFICATION_TYPE_NEWSSTAND
],
success: eventSuccess,
error: eventError,
callback: eventCallback
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment