iOS 位置服务 Enabled/Disabled 应用程序关闭时的事件

iOS Location Services Enabled/Disabled event when application closed

我目前正在使用 CLLocationManager 始终跟踪地理围栏,即使应用程序在后台也是如此。当定位服务为 enabled/disabled.

时,我似乎无法找到监听方法

是否可以侦听位置服务 enable/disable 事件,或者当您的特定应用程序关闭时位置是 enabled/disabled?

请注意我使用的是 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*/ };
    }
}

对 class 方法的调用 [CLLocationManager locationServicesEnabled] returns BOOL 指示是否启用定位服务。

如果用户禁用定位服务,locationManager:didChangeAuthorizationStatus: 将在 CLLocationManagerDelegate 上调用。

因此,如果您有一个class符合CLLocationManagerDelegate并实现了locationManager:didChangeAuthorizationStatus:,您应该能够处理用户的禁用事件。