如何判断当前App是否允许使用系统定位功能

如题解答:利用CLLocationManager的一个类方法

1
2
3
4
5
6
7
8
9
10
11
+ (CLAuthorizationStatus)authorizationStatus
// 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
3
4
5
// 判断本地定位服务开启
if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied){
    // 提示用户开启定位服务,PS:iOS8系统会自动检测额
    [SAAlertView showMessage:@"请在系统设置中打开“定位服务”来允许“XXX”确定您的位置"];
}

Leave a Reply