花了几天时间尝试解决这个问题,但无法找到任何有效的解决方案。我已经检查了stackoverflow上的所有帖子,并尝试了他们提出的所有解决方案,但似乎没有什么起作用。我还尝试了CLLocation的苹果测试项目,结果很好。我从苹果测试项目中使用了一些片段。
https://developer.apple.com/library/ios/samplecode/LocateMe/Listings/README_md.html
但我的代码根本不起作用,DidupdateToLocation从未被调用。
以下是我的代码(在viewDidLoad中):
_locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
// This is the most important property to set for the manager. It ultimately determines how the manager will
// attempt to acquire location and thus, the amount of power that will be consumed.
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// Once configured, the location manager must be "started"
//
// for iOS 8, specific user level permission is required,
// "when-in-use" authorization grants access to the user's location
//
// important: be sure to include NSLocationWhenInUseUsageDescription along with its
// explanation string in your Info.plist or startUpdatingLocation will not work.
//
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
[self performSelector:@selector(stopUpdatingLocationWithMessage:)
withObject:@"Timed Out"
afterDelay:30];
我已经检查确认了locationServicesEnabled已启用。
我已将NSLoationWhenInUseUsageDescription属性添加到info.plist文件中。是否还需要添加其他属性或启用任何服务?
我真的不知道自己做错了什么。有人能帮我吗?