在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
仍然会给出错误 –