在iOS8上你寫下面的代碼
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
// Code to check if the app can respond to the new selector found in iOS 8. If so, request it.
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
// Or [self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
而且您還必須在您的plist文件中添加NSLocationAlwaysUsageDescription和要顯示的應用程序消息。
檢查本教程http://www.devfright.com/ios-6-core-location-tutorial/
你需要做的第一件事情就是添加下列鍵的一個或兩個,以你的Info.plist文件:NSLocationWhenInUseUsageDescription, NSLocationAlwaysUsageDescription – Sport
http://nshipster.com/core-location -in-ios-8/ – Sport
仍然會給出錯誤 –