更改时CLLocationManager locationServicesEnabled事件

时间:2014-01-06 11:24:11

标签: ios

如何监控[CLLocationManager locationServicesEnabled]何时更改?我需要delegatenotification等内容。

3 个答案:

答案 0 :(得分:4)

使用CLLocationManager的delagte方法

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

这些是文档中的CLAuthorizationStatus描述:

    > typedef enum {
    >     kCLAuthorizationStatusNotDetermined = 0, // User has not yet made a choice with regards to this application
    >     kCLAuthorizationStatusRestricted,        // This application is not authorized to use location services.  Due
    >                                              // to active restrictions on location services, the user cannot change
    >                                              // this status, and may not have personally denied authorization
    >     kCLAuthorizationStatusDenied,            // User has explicitly denied authorization for this application, or
    >                                              // location services are disabled in Settings
    >     kCLAuthorizationStatusAuthorized         // User has authorized this application to use location services 
} CLAuthorizationStatus;

答案 1 :(得分:2)

您可以使用locationManager:didChangeAuthorizationStatus:方法执行此操作:

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
  //Check new status
}

答案 2 :(得分:1)

由于iOS在用户更改全局位置服务设置时没有本机回调/通知,因此我们无法直接处理。但你可以参加

[CLLocationManager locationServicesEnabled]

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { //Check new status }

达到预期的效果,如:

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
 if (![ CLLocationManager locationServicesEnabled]) {
  //perform action when location service is disabled
  }
}

虽然确实理解如果权限已被拒绝且位置设置已更改,您将不会收到此回调。