//聯系人:石虎QQ: 1224614774昵稱:嗡嘛呢叭咪哄
1、需要手動調用CLLocationManager對象的requestAlwaysAuthorization方法。
2、調用該方法需要在Info.plist中設置NSLocationAlwaysUsageDescription的字符串,這個值 (NSString *)會顯示在系統提示框中 ;不要自己加值就是(Boolean),選yes;
3、在代碼中添加代理方法
/* 定位服務狀態改變時調用/
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
switch (status) {
case kCLAuthorizationStatusNotDetermined:
{
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
NSLog(@"用戶還未決定授權");
break;
}
case kCLAuthorizationStatusRestricted:
{
NSLog(@"訪問受限");
break;
}
case kCLAuthorizationStatusDenied:
{
// 類方法,判斷是否開啟定位服務
if ([CLLocationManager locationServicesEnabled]) {
NSLog(@"定位服務開啟,被拒絕");
} else {
NSLog(@"定位服務關閉,不可用");
}
break;
}
case kCLAuthorizationStatusAuthorizedAlways:
{
NSLog(@"獲得前后臺授權");
break;
}
case kCLAuthorizationStatusAuthorizedWhenInUse:
{
NSLog(@"獲得前臺授權");
break;
}
default:
break;
}
}
謝謝!!!