【发布时间】:2013-08-08 09:59:05
【问题描述】:
我暂时禁用了位置服务和我的应用程序的权限,以便我可以测试一些处理它们不可用的情况的代码。再次打开它们后,现在无法使用以下代码获取我的位置:
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
CLLocation *currentLocation = locationManager.location;
[locationManager stopUpdatingLocation];
运行此代码后,locationManager.location 等于 nil。
我在运行 iOS 6 的 iPad 上运行它。
【问题讨论】:
-
不清楚您是使用
CLLocationManagerDelegate还是仅使用locationManager.location属性 -
我没有使用代理。
-
我从来没有在没有委托的情况下使用过 CLLocationManager,但我认为如果您关闭定位服务,那么
location属性可能为零。这就是CLLocationManagerDelegate存在的原因。还给CLLocationManager时间来检索位置。此外,有时返回的第一个location可能是旧的,所以我只需更改该代码
标签: iphone ios objective-c ipad cllocationmanager