2
我目前使用CLLocationManager
来始终跟踪地理围栏,即使应用程序在后台也是如此。当位置服务启用/禁用时,我似乎无法找到一种方法来侦听。iOS位置服务应用程序关闭时启用/禁用事件
是否有可能侦听位置服务启用/禁用事件,或者当应用程序关闭时针对特定应用程序启用/禁用位置?
请注意我正在使用Xamarin,但Objective-C代码很好。
public class LocationManager
{
protected CLLocationManager locationManager;
public LocationManger()
{
this.locationManager = new CLLocationManger();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
locationManager.RequestAlwaysAuthorization();
}
// ... get array of CLCircularRegion and start listening to each
// locationManager events...
locationManager.RegionEntered += (sender, e) => { /*stuff*/ };
locationManager.RegionLeft += (sender, e) => { /*stuff*/ };
locationManager.DidDetermineState += (sender, e) => { /*stuff*/ };
//locationaManager.SomeSortOfLocationServiceEnableDisableEvent += (sender, e) => { /*stuff*/ };
}
}
是的,但没有告诉我何时位置服务发生变化。 –
我用处理授权状态更改的委托方法更新了我的答案。这有帮助吗? – Daniel
这似乎并不完美,但看起来它是iOS所能提供的最佳选择。谢谢丹尼尔。杰瑞德,没问题, –