且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测用户选择不允许MKMapView for iphone

更新时间:2022-12-30 10:41:46

为了监控变化实现 CLLocationManagerDelegate 方法所需的位置服务的授权状态 locationManager:didChangeAuthorizationStatus:获取类似

In order to monitor the changes in the authorization status for the location services you need to implement the CLLocationManagerDelegate method locationManager:didChangeAuthorizationStatus: obtaining something like

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

    if (status == kCLAuthorizationStatusDenied) {
        // permission denied
    }
    else if (status == kCLAuthorizationStatusAuthorized) {
        // permission granted
    }
}

有关可能的授权状态及其说明的完整列表,您可以查看 CLAuthorizationStatus

For a complete list of the possible authorization statuses and their description you can check out the official documentation of CLAuthorizationStatus.

编辑

您可能已经有 CLLocationManager 的实例,让我们称之为的LocationManager 。然后,为了实现您的委托,您将您的类符合 CLLocationManagerDelegate 协议(您可以在类的标题中声明它 - 这不是强制性的,但它会为您提供一些静态检查设施)并将其分配给 locationManager 委托属性,如下所示:

You probably have already your instance of CLLocationManager, let's call it locationManager. Then in order to implement your delegate you conform your class to the CLLocationManagerDelegate protocol (you can declare it in the header of class -- this is not mandatory but it will provide you some static checking facilities) and assign it to the delegate property of locationManager like follows:

locationManager.delegate = self; //assuming that self is gonna be the delegate

如果按照说明执行了所有操作,您的控制器将被调用每次授权更改时,如文档所述:

If you did everything as explained your controller will be called at every authorization change, as stated by the documentation:


只要应用程序使用位置服务的能力发生变化,就会调用此方法。

this method is called whenever the application’s ability to use location services changes.