IOS-iOS 8 : Location Services not working(iOS 8 定位應用定位失敗)


如果是xcode6和ios 8的話,需要調用 CLLocationManager requestAlwaysAuthorization 方法,具體步驟如下:

1. @interface里:
CLLocationManager *locationManager;
2. 初始化:
locationManager = [[CLLocationManager alloc] init];
3. 調用請求:
[locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation];
4. 在 info.plist里加入:
NSLocationWhenInUseDescription,允許在前台獲取GPS的描述
NSLocationAlwaysUsageDescription,允許在后台獲取GPS的描述

ps:調用請求前加上ios版本判斷就完美了。

完美一下:

// 判斷是否 iOS 8
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization]; // 永久授權
[self.locationManager requestWhenInUseAuthorization]; //使用中授權
}
[self.locationManager startUpdatingLocation];


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM