简体   繁体   English

Xamarin iOS Geolocator后台服务约30分钟后死亡

[英]Xamarin iOS Geolocator Background Service Dying after about 30 mins

I am currently using the Xamarin geolocation plugin found here: 我目前正在使用Xamarin地理位置插件,可在此处找到:

https://github.com/jamesmontemagno/GeolocatorPlugin https://github.com/jamesmontemagno/GeolocatorPlugin

To perform location services in an app I am building using Xamarin Forms (PCL). 为了在应用程序中执行位置服务,我正在使用Xamarin Forms(PCL)构建。 I believe I have added in the relevant permission settings to allow for this. 我相信我已经添加了相关的权限设置以允许这样做。

The GPS works great while the app is active and locked (but with app in the foreground). 当应用处于活动状态且已锁定(但应用在前景中)时,GPS可以很好地工作。 However when the app is pushed to the background on iOS by clicking the "home" button, it still tracks the user and highlights the "App is Using Your Location" message as I would expect, however after a certain amount of time between 30-40 minutes, this message disappears, and the GPS appears to stop tracking the user until they bring the app back to the foreground. 但是,当通过单击“主页”按钮将应用程序推到iOS的后台时,它仍然会跟踪用户并突出显示“应用程序正在使用您的位置”消息,但是,在30- 40分钟后,此消息消失,GPS似乎停止跟踪用户,直到他们将应用程序带回前台。

Once the app has been brought to the foreground, it can be backgrounded once again for another 30-40 minutes to repeat the cycle. 将应用程序带到前台后,可以再次将其后台运行30-40分钟,以重复该循环。

I have ensured that the locator object allows background updates: 我确保locator对象允许后台更新:

public static Plugin.Geolocator.Abstractions.IGeolocator locator;
locator = CrossGeolocator.Current;
locator.AllowsBackgroundUpdates = true;
locator.DesiredAccuracy = 20;

A call to .PausesLocationUpdatesAutomatically shows that this is false (which I believe is the default). 调用.PausesLocationUpdatesAutomatically显示这是错误的(我相信这是默认值)。

Edit 编辑

I have the following keys to info.plist: 我有以下info.plist键:

NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription

And enabled background location updates: 并启用了后台位置更新:

在此处输入图片说明

在此处输入图片说明

However I have not enabled background fetching as Girish has in the answers, is this something I need to do? 但是,我没有像Girish那样启用后台获取功能,这是我需要做的吗?

Please check whether you have enabled the background mode for location update. 请检查您是否启用了后台模式以进行位置更新。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM