Phonegap iOS與背景中的地理位置

[英]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.

我正在開發一個使用地理定位服務的應用程序。在應用程序處於前台的IOS上,一切正常。當應用程序進入后台時(大約30-40分鍾后),但地理編碼停止工作,我不再獲得更改位置事件。在后台期間,應用程序成功地將JSON的時間戳和lng / lat每隔幾秒鍾成功地發送到我的遠程服務器,因此我知道它在該有限時間內正在工作。

My configuration is:


Frame work: PhoneGap 2.5

框架工作:PhoneGap 2.5

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

設備:iOS(在4,4和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

插件:Cordova的PowerManagement插件(2.0+)作者:Wolfgang Koller - GOFG Sports Computer

startWatch Function:

function onDeviceReady() {
    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-info plist包括:

"App registers for location updates" under "Required background modes"

config.xml includes:

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


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


2 个解决方案



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.




I'm not sure but maybe IOS is like Android for this function : Creating an Android Service with Phonegap? (Have phonegap app run even when closed)

我不確定,但也許IOS就像Android這個功能:使用Phonegap創建Android服務? (即使關閉,也可以運行phonegap app)

So, Javascript will stop when app goes in background or a few sec(or min) after. Moreover, PowerManagement isn't the solution. PowerManagement allows you to tell the OS : "Hey guy, I have an which need to run even if the phone is lock, so please don't turn off the CPU (or Screen) when I lock the phone.

因此,當應用程序進入后台或幾秒鍾(或分鍾)后,Javascript將停止。而且,PowerManagement不是解決方案。 PowerManagement允許你告訴操作系統:“嘿,我有一個即使手機鎖定也需要運行,所以當我鎖定手機時請不要關閉CPU(或屏幕)。

Maybe try this (only for IOS > 5 and WP8) : I'm a IOS pro, I'm an Android Pro and I use Cordova and this plugin (PowerManagement) and it doesn't do what you think.

也許試試這個(僅適用於IOS> 5和WP8):我是IOS專業版,我是Android專業版,我使用Cordova和這個插件(PowerManagement)並沒有按照你的想法行事。

I hope I help you.





粤ICP备14056181号  © 2014-2021