花了几天试图解决这个问题,但无法找到任何有效的解决方案。我已经检查了所有在stackoverflow的帖子,并尝试了所有的解决方案,似乎没有任何工作。我也尝试了CLLocation的苹果测试项目,对我来说工作正常。我以前的点点滴滴,从苹果的测试项目CLLocation didupdatetolocation不叫
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文件。我需要添加或启用任何服务还有其他任何属性吗?
我不能为上帝的爱搞清楚我做错了什么。有人可以帮我解决这个问题。
btw会弹出授权警报? – 2014-10-06 16:34:58
授权警报不会弹出 – dogwasstar 2014-10-07 00:05:43
然后我猜didChangeAuthorizationStatus回调既不会被调用,对吧?该应用的位置服务已启用? (设置/隐私/位置服务)您确定您向.plist添加了正确的密钥吗? – 2014-10-07 07:14:08