xcode6打開之前xcode5工程,發現程序不能定位,包括iOS8模擬器,真機都不能定位?代碼經檢查沒有問題,後來查找蘋果Ios8升級差別策略,發現Ios8對定位處理作了一些調整,工程升級到xcode6編譯時須要iOS8 要本身寫受權,否則沒權限定位。修改點以下:
1: 在Info.plist中加入兩個缺省沒有的字段 ,值均設置爲YES
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
2:啓動定位代碼[locationManager startUpdatingLocation] 前,須要增長Ios8判斷處理html
if ([[[UIDevice currentDevice] systemVersion] doubleValue] > 8.0) {
//設置定位權限 僅ios8有意義
[locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];ios
3:實現 CLLocationManagerDelegate 代理 - (void)locationManagerCLLocationManager *)manager didChangeAuthorizationStatus
CLAuthorizationStatus)status 方法,注意:如不增長該代理方法實現,會致使首次調用定位時候沒法彈出 」程序啓動定位提示框「 致使定位失敗xcode
#pragma mark - 受權定位
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
NSLog(@"調用代理");
switch (status) {
case kCLAuthorizationStatusNotDetermined:{
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
}
break;
default:{
}
break;
}
}spa