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