Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Created September 16, 2013 21:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benbahrenburg/6587027 to your computer and use it in GitHub Desktop.
Save benbahrenburg/6587027 to your computer and use it in GitHub Desktop.
sample app.js showing background fetch.
// 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 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 1', window:win1
});
var label1 = Titanium.UI.createLabel({
color:'#999',
text:'I am Window 1',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
win1.add(label1);
tabGroup.addTab(tab1);
// open tab group
tabGroup.open();
var wasFired = false;
Ti.App.iOS.setMinimumBackgroundFetchInterval(900);
Ti.App.iOS.addEventListener('fetch',function(e){
Ti.API.info("FETCH - fired in background");
wasFired = true;
});
Ti.App.addEventListener('paused', function(e){
Ti.API.info("at this point Ti needs a background service to keep Kroll Happy");
var service = Ti.App.iOS.registerBackgroundService({url:'bg.js'});
});
Ti.App.addEventListener('resumed', function(e){
if(wasFired){
alert("Success - fetch fired");
}else{
alert("Failure");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment