【发布时间】:2014-11-30 20:25:40
【问题描述】:
花了几天时间试图解决这个问题,但找不到任何可行的解决方案。我检查了 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 文件中。我需要添加或启用任何服务的其他属性吗??
看在上帝的份上,我无法弄清楚我做错了什么。有人可以帮我解决这个问题吗?
【问题讨论】:
-
btw 授权提示弹出?
-
授权提示没有弹出
-
那么我猜 didChangeAuthorizationStatus 回调没有被调用,对吧?应用程序的位置服务是否已启用? (设置/隐私/位置服务)您确定您在 .plist 中添加了正确的密钥吗?
-
嘿,大卫,是的,我已经检查过我正在向 plist 添加正确的密钥。仍然无法让它工作。不得不把这件事搁置一段时间。今天会尝试修复它
标签: ios objective-c gps location