My phonegap app tracks a users location via watchPosition() and it is important for the app to continuously run.
4 Answers
iOS provides a service that notifies your app of significant location changes. That's not something you can access directly in JavaScript, but you can create a plugin for PhoneGap (or just modify your app's native code) to register for those notifications and call a routine in JavaScript.
This will do it:
[UIApplication sharedApplication].idleTimerDisabled = YES;
-
I'm pretty sure this will only prevent the app from going to sleep while the app is still in foreground. May 18, 2012 at 23:44
-
2Where would I insert this line of code? Could you paste an example? Thankyou– jt40May 18, 2012 at 23:44
-
Yes Kaan this is right. This will keep the app always active in the foreground and prevent it from sleeping. You can paste this inside your native code app delegate class inside the application:didfinishlaunching:withoptions method. As far as running in the background caleb is correct, you can register your app to run in the background and receive continuous ( or non continuous with some clever hacking) updates but this is a little bit more involved if you aren't writing this natively May 19, 2012 at 1:50
There are limitations to frameworks such as PhoneGap.
If you need to be able to have it running in the background, getting location information, your best bet is to write is a native application, so you can take advantage of what IOS offers.
You may want to read this, to get an understanding of when apps can be running in the background:
You can in theory run a JS app in the background, but you would first need to make a PhoneGap plugin that provides access to iOS background processing.