OGeek|极客世界-中国程序员成长平台

标题: 应用程序关闭时的 iOS 定位服务启用/禁用事件 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:50
标题: 应用程序关闭时的 iOS 定位服务启用/禁用事件

我目前正在使用 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*/ };
    }
}



Best Answer-推荐答案


调用类方法 [CLLocationManager locationServicesEnabled] 返回一个 BOOL 指示是否启用位置服务。

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

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

关于应用程序关闭时的 iOS 定位服务启用/禁用事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33090336/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4