iOS 解決iOS 地圖獲取位置提示框不彈出

//聯系人:石虎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;

}

}

謝謝!!!

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容