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.

我已經在PhoneGap的背景下閱讀了一些關於地理定位的討論,但我仍然遇到了問題。

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

iOS版本:7.0.4

Xcode: Version 5.0.2 (5A3005)

Xcode:版本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

插件:Cordova的PowerManagement插件(2.0+)作者: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-info plist包括:

"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?

我想知道有沒有辦法確保PhoneGap中的JavaScript在應用程序處於后台時不斷運行?

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?

我是否需要設置Wakelock獲取/發布以確保Powermanagement插件在iOS中高效工作?有人可能建議不同的插件或配置/代碼我可能錯過了嗎?

Cheers, Wayne Gardner Sydney Australia

干杯,韋恩加德納悉尼澳大利亞

2 个解决方案

#1


5  

Try out mine. Works great for iOS and Android

試試我的。適用於iOS和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

#2


2  

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) : https://github.com/katzer/cordova-plugin-background-mode 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):https://github.com/katzer/cordova-plugin-background-mode我是IOS專業版,我是Android專業版,我使用Cordova和這個插件(PowerManagement)並沒有按照你的想法行事。

I hope I help you.

我希望我幫助你。

Coco


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/11/20/725e72ba9e063e8a2f9993241d620aa2.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com