IOS8 IOS9 高德地圖彈出是否允許定位框功能程式碼
第一步:在info.plist檔案新增兩個欄位
NSLocationAlwaysUsageDescription - > YES
第二步:
- (CLLocationManager *)locationManager
{
if (!locationManager) {
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = (id)self;
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager requestAlwaysAuthorization];
locationManager.distanceFilter =kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
}
return locationManager;
}
第三步
/*使用者變更了程式的定位服務狀態*/
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
switch (status) {
casekCLAuthorizationStatusNotDetermined:
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
break;
default:
break;
}
}