【发布时间】:2015-09-30 10:34:23
【问题描述】:
我正在开发 ios8+ 中的应用程序,我必须在其中获取用户的位置。当我在屏幕(视图控制器)中使用 CLLocationManager 时,我能够获取位置。但是当我尝试直接从 AppDelegate 获取位置时,似乎出现了一些问题,我没有得到任何位置(流程没有进入委托方法)。 有人可以帮我解决这个问题吗?
这是我使用的代码:
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];
你能帮我解决这个问题吗?谢谢
【问题讨论】:
标签: ios objective-c iphone gps core-location