Created
January 22, 2014 23:14
-
-
Save wpccolorblind/8569411 to your computer and use it in GitHub Desktop.
Titanium fetch and silentpush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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