应用程序关闭时启用/禁用iOS位置服务事件
我目前正在使用应用程序关闭时启用/禁用iOS位置服务事件,ios,location,cllocationmanager,Ios,Location,Cllocationmanager,我目前正在使用CLLocationManager始终跟踪地理围栏,即使应用程序位于后台。在启用/禁用位置服务时,我似乎找不到监听的方法 是否可以侦听位置服务启用/禁用事件,或者在应用程序关闭时为特定应用程序启用/禁用位置 请注意,我使用的是Xamarin,但Objective-C代码可以 public class LocationManager { protected CLLocationManager locationManager; public LocationMange
CLLocationManager
始终跟踪地理围栏,即使应用程序位于后台。在启用/禁用位置服务时,我似乎找不到监听的方法
是否可以侦听位置服务启用/禁用事件,或者在应用程序关闭时为特定应用程序启用/禁用位置
请注意,我使用的是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*/ };
}
}
调用类方法
[CLLocationManager locationServicesEnabled]
返回一个BOOL
,指示是否启用了位置服务
如果用户禁用位置服务,则将在CLLocationManagerDelegate
上调用locationManager:didChangeAuthorizationStatus:
因此,如果您有一个类符合
CLLocationManagerDelegate
并实现locationManager:didChangeAuthorizationStatus:
,您应该能够由用户处理禁用事件。是,但这不会告诉我位置服务何时更改。我已使用处理授权状态更改的委托方法更新了答案。这有帮助吗?这似乎并不完美,但它看起来是iOS提供的最好的产品。谢谢丹尼尔,没问题,杰瑞德。我很高兴你至少可以从iOS那里得到满足你需要的东西。