Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing Javascript in background using Phonegap

I've created an application that will need to fire Javascript events every "X" minutes. I'm using phone gap build to deploy on Android/iPhone/Blackberry, but I'm of course stuck, as the Javascript timer doesn't fire in the background (when they minimize the app). I was wondering if Phonegap had some sort of ability to fire Javascript events while the app is running in the background.

Or is there ANY way to accomplish this easily across these major phones? I just need to fire an ajax call with the geolocation info from the phones.

like image 616
Trevor Avatar asked Sep 28 '11 15:09

Trevor


2 Answers

Yes you can do it, there's a PhoneGap plugin that does exactly what you need:

PhoneGap + Background.js https://github.com/jocull/phonegap-backgroundjs

Be careful configuring your config.xml

like image 88
Nico Westerdale Avatar answered Nov 08 '22 14:11

Nico Westerdale


Currently, phone gap doesn't have this as an option. There are many requests out there for this sort of thing, but I think people are getting tripped up by the TOS for background events for iOS. Regardless, a phone gap plugin would do it as @Chase mentioned, but of course that requires native code writing.

I'm assuming you're wanting to push geo locations every x seconds/minutes so that your server knows where the phone is at any point in time (as long as the app is open or minimized)? That's one limitation of Loopt, is that it can't grab those locations in the background - hence the whole 'ping' action in the app.

like image 31
swatkins Avatar answered Nov 08 '22 15:11

swatkins