title: Phonegap iOS with Geolocation in Background
body: <p>I have read some of the discussions on geolocation in background on PhoneGap, but am still having problems.</p>
  
  <p>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.</p>
  
  <p>My configuration is:</p>
  
  <p>Frame work: PhoneGap 2.5</p>
  
  <p>Devices: iOS (tested on 4, 4s &amp; 5 iPhone &amp; iPad4)</p>
  
  <p>iOS Version: 7.0.4</p>
  
  <p>Xcode: Version 5.0.2 (5A3005)</p>
  
  <p>Plugin: 
  PowerManagement Plugin for Cordova (2.0+)
  by Wolfgang Koller - GOFG Sports Computer
  <a href="https://github.com/purplecabbage/phonegap-plugins/tree/master/iOS/PowerManagement" rel="nofollow">https://github.com/purplecabbage/phonegap-plugins/tree/master/iOS/PowerManagement</a></p>
  
  <p>startWatch Function:</p>
  
  <pre><code>function onDeviceReady() {
      startWatch();
      function startWatch() {
          var options = { enableHighAccuracy: true, timeout: 3100, maximumAge: 0 }; 
          watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);            
          timerID = setInterval ( updateLocation, 3000 ); 
      }
  .
  .
  </code></pre>
  
  <p>App-info plist Includes:</p>
  
  <pre><code>"App registers for location updates" under "Required background modes"
  &amp;
  &lt;key&gt;UIBackgroundModes&lt;/key&gt;
  &lt;array&gt;
      &lt;string&gt;location&lt;/string&gt;
  &lt;/array&gt;
  </code></pre>
  
  <p>config.xml includes:</p>
  
  <pre><code>&lt;plugin name="PowerManagement" value="PowerManagement" /&gt;
  </code></pre>
  
  <p>Questions:</p>
  
  <p>I was wondering is there a way to ensure JavaScript in PhoneGap runs continually when the app is in the background?</p>
  
  <p>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?</p>
  
  <p>Cheers,
  Wayne Gardner
  Sydney Australia</p>