Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
应用程序关闭时启用/禁用iOS位置服务事件_Ios_Location_Cllocationmanager - Fatal编程技术网

应用程序关闭时启用/禁用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那里得到满足你需要的东西。