PhoneGap + Background.js
Please note that this code is now very old, but you can read more on my old (dead, archived) blog: https://web.archive.org/web/20170203171054/http://www.codefromjames.com/wordpress/?p=154
Uses a sleep countdown timer paired with a UIBackgroundTaskIdentifier. The magic looks like this:
Add the BackgroundJS plugin to your Phonegap project:
phonegap local plugin add <location of BackgroundJS git repository>
...enable the plugin in
Get a block of secondsi (e.g. use a background thread for 10 seconds):
Run in the background indefinitely:
Stop running background tasks immediately:
Be careful when using this, as Apple specifications are picky. If you're not using background audio or tracking location, your app may be rejected for background tasking guidelines. Read up, and write some code!
ALSO... Please don't kill my battery life just because you backgrounded more than you had to. You're not a special snowflake (yet) so play by the rules. Code smart, and make your app work right!
Have a patch? Pull requests appreciated!