Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap iOS with Geolocation in Background

I have read some of the discussions on geolocation in background on PhoneGap, but am still having problems.

I'm working on an application that uses geolocation services. On IOS when application is in foreground all works fine. When the application goes to background (after around 30-40 minutes) however the geocoding stops working and I don't get the change position event anymore. During the period in background the application successfully JSON's a time stamp and lng/lat every few seconds to my remote server so I know it's working during that limited period.

My configuration is:

Frame work: PhoneGap 2.5

Devices: iOS (tested on 4, 4s & 5 iPhone & iPad4)

iOS Version: 7.0.4

Xcode: Version 5.0.2 (5A3005)

Plugin: PowerManagement Plugin for Cordova (2.0+) by Wolfgang Koller - GOFG Sports Computer https://github.com/purplecabbage/phonegap-plugins/tree/master/iOS/PowerManagement

startWatch Function:

function onDeviceReady() {
    startWatch();
    function startWatch() {
        var options = { enableHighAccuracy: true, timeout: 3100, maximumAge: 0 }; 
        watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);            
        timerID = setInterval ( updateLocation, 3000 ); 
    }
.
.

App-info plist Includes:

"App registers for location updates" under "Required background modes"
&
<key>UIBackgroundModes</key>
<array>
    <string>location</string>
</array>

config.xml includes:

<plugin name="PowerManagement" value="PowerManagement" />

Questions:

I was wondering is there a way to ensure JavaScript in PhoneGap runs continually when the app is in the background?

Do I need to set Wakelock acquired/ release to ensure the Powermanagement plugin work efficiently in iOS? Could someone suggest a different plugin maybe or config/code I may have missed?

Cheers, Wayne Gardner Sydney Australia

like image 755
Enyawg Avatar asked Mar 22 '23 13:03

Enyawg


1 Answers

Try out mine. Works great for iOS and Android

The plugin has a debug mode where it emits sounds for its life-cycle events (location change, exit stationary-region, and more) which is great for getting instant feedback while field-testing.

https://github.com/transistorsoft/cordova-background-geolocation-lt

like image 161
christocracy Avatar answered Apr 01 '23 00:04

christocracy