I do not understand why the timer runs in the background for 9 minutes but when I rule the timer to 15 minutes it no longer works even in the background?
app.js
var service; Ti.App.addEventListener('pause',function(e){ service = Ti.App.iOS.registerBackgroundService({url:'bg.js'}); });
bg.js
var Min = 15; var MiliSec = (Min*60)*1000); setTimeout(function(){ var xhr_power = Ti.Network.createHTTPClient(); xhr_power.open("GET","http://www.monsite.fr"); xhr_power.onload = function() { try { Ti.API.info('ok'); } catch(E) { Ti.API.info('Error : '+E); } }; // Get the data xhr_power.send(); }, MiliSec;
11 Answers
The app on iOs gets killed after 10 minutes when put in the background unless you set the background mode, but in this case restrictions apply. http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html
scroll to UIBackgroundModes
?I have a solution that works but it is not the best, I created an audio object then I start reading the application is in the background, I created an empty sound is read loop which allows to have my code that works in the background :
var player = Ti.Media.createSound({url:"sons.mp3", looping:true, allowBackground:true}); Ti.Media.defaultAudioSessionMode = Ti.Media.AUDIO_SESSION_MODE_PLAYBACK;
Because, so far as I know, an app cannot stay more than 10 minutes in background before iOS somehow terminates it.
I tried with
<key>UIBackgroundModes</key> <array> <string>newsstand-content</string> </array>but I still have the same problem you advise me what to UIBackgroundModes Value ? Thank you for answer
I am try your methode but don't work. Thank
I think that's an option, but Apple wouldn't accept that I think, too... Or do you have a productive application in the AppStore which runs with this solution in the background?
yes I have an application that is Freebox Sleep, used for this application, you need to be in France and have freebox if the app does not function iTunes App => Freebox Sleep
Okay, fresh! :) But i mean, your application must something do with audio in the background. Otherwise apple will reject it, you app use the audio-function for background and apple allow that it this case. But as example for an tracking-app (should use "location" BackgroundMode) I can't put "audio" in the tiapp.xml for background-use.
I then had the chance because my application has passed the validation :)
Lucky guy. :) One question: How did you create the "empty" mp3-file?
I created a silent mp3 file with garage band, if you want I send you by mail
Your Answer
Think you can help? Login to answer this question!