Skip to content

Instantly share code, notes, and snippets.

@alanleard
Created January 7, 2012 00:12
Show Gist options
  • Save alanleard/1573192 to your computer and use it in GitHub Desktop.
Save alanleard/1573192 to your computer and use it in GitHub Desktop.
Remote Notification in App Action
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Ti.UI.createWindow({
backgroundColor: 'white'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 1',
window:win1
});
Titanium.UrbanAirship = Ti.UrbanAirship = require('ti.urbanairship');
Ti.UrbanAirship.options = {
APP_STORE_OR_AD_HOC_BUILD: false,
//PRODUCTION_APP_KEY: '=== YOUR PROD APP KEY ===',
//PRODUCTION_APP_SECRET: '=== YOUR PROD APP SECRET ===',
DEVELOPMENT_APP_KEY: '=== YOUR DEV APP KEY ===',
DEVELOPMENT_APP_SECRET: '=== YOUR DEV APP SECRET ==='',
LOGGING_ENABLED: true
};
var b = Ti.UI.createButton({
title: 'Open UA Inbox',
width: 200, height: 40,
top: 25
});
b.addEventListener('click', function() {
// Open default mailbox
Ti.UrbanAirship.displayInbox({ animated:true });
});
win1.add(b);
var label = Ti.UI.createLabel({
text:'Testing UA',
top: 95
});
win1.add(label);
Ti.Network.registerForPushNotifications({
types:[
Ti.Network.NOTIFICATION_TYPE_BADGE,
Ti.Network.NOTIFICATION_TYPE_ALERT,
Ti.Network.NOTIFICATION_TYPE_SOUND
],
success: function(e) {
var token = e.deviceToken;
//alert(e.deviceToken);
//Ti.API.log(token);
Ti.UrbanAirship.registerDevice(token);
//alert(JSON.stringify(e));
label.text += '\nGot it: '+ e.alert;
label.text += '\n'+ e.badge;
b.enabled = true;
},
error: function(e) {
alert("Error: " + e.error);
},
callback: function(e) {
// Ti.UrbanAirship.handleNotification(e.data);
label.text += '\n => '+ JSON.stringify(e.data);
label.text += '\n > '+ JSON.stringify(e.data.alert);
var tabTo = e.data.tab;
//var pageTo = e.data.page;
label.text += '\n > '+ tabTo;
tabGroup.setActiveTab(tabTo);
//page.scrollToView(pageTo);
}
});
function eventCallback(e) {
if (e.clicked) {
Ti.API.info('User clicked a notification');
} else {
Ti.API.info('Push message received');
}
Ti.API.info(' Message: ' + e.message);
Ti.API.info(' Payload: ' + e.payload);
label.text = 'Got it: '+ e.message;
label.text += '\n'+ e.payload;
}
var win2 = Ti.UI.createWindow({
backgroundColor: 'white'
});
var tab2 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 2',
window:win2
});
var win3 = Ti.UI.createWindow({
backgroundColor: 'white'
});
var tab3 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 3',
window:win3
});
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tabGroup.addTab(tab3);
tabGroup.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment