Skip to content

Instantly share code, notes, and snippets.

@wpccolorblind
Created January 22, 2014 23:14
Show Gist options
  • Save wpccolorblind/8569411 to your computer and use it in GitHub Desktop.
Save wpccolorblind/8569411 to your computer and use it in GitHub Desktop.
Titanium fetch and silentpush
Ti.API.info("FETCH INTERVAL :: " + Ti.App.iOS.BACKGROUNDFETCHINTERVAL_MIN);
Ti.App.iOS.setMinimumBackgroundFetchInterval(Ti.App.iOS.BACKGROUNDFETCHINTERVAL_MIN);
Ti.App.iOS.addEventListener("backgroundfetch", function(e){
Ti.API.info("BACKGROUND FETCH :: " + JSON.stringify(e))
var fetchID = e.handlerId;
xhr = Titanium.Network.createHTTPClient({
onload: function() {
Ti.API.info("API this.responseText :: " + this.responseText);
try {
res = JSON.parse(this.responseText);
} catch (e) {
Ti.API.info("ERROR API :: " + this.responseText);
}
Ti.App.iOS.scheduleLocalNotification({
alertBody:"res : " + JSON.stringify(res),
date:new Date().getTime()
});
Ti.App.iOS.endBackgroundHandler(fetchID);
},
onerror: function(e) {
Ti.API.info("REQUEST ERROR: " + JSON.stringify(e));
}
});
xhr.open("POST", /*api url*/);
xhr.send({});
})
Ti.App.iOS.addEventListener("silentpush", function(e){
Ti.API.info("silentpush :: " + JSON.stringify(e))
Ti.App.iOS.scheduleLocalNotification({
alertBody:"silentpush stuff initiated...",
date:new Date().getTime()
});
Ti.App.iOS.endBackgroundHandler(e.handlerId);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment