[英]didUpdateLocations: method not called on device running iOS 7
I am facing a strange problem. 我面临一个奇怪的问题。 I am using
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
to get device location. 我正在使用
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
获取设备位置。 It is working fine on simulator (iOS 6 and iOS 7)
and iPhone 4S running iOS 6.1.3
. 在
simulator (iOS 6 and iOS 7)
和iPhone 4S running iOS 6.1.3
。 It is also working fine when I connect iPhone 4 running iOS 7
to system and install the app but as soon as I unplug the device and re-run the app, this method doesn't get called and I don't get the location. 当我将
iPhone 4 running iOS 7
连接到系统并安装该应用程序时,它也可以正常工作,但是当我拔出设备并重新运行该应用程序时,此方法不会被调用,并且我也无法获取位置。 How can I overcome this issue? 我该如何克服这个问题?
How did you setup you location Manager? 您是如何设置位置管理器的?
Do you have in your interface: 您的界面中是否有:
@interface ViewController : UIViewController <CLLocationManagerDelegate> {
@property (strong, nonatomic) CLLocationManager *locationManager;
}
Then in implementation in viewDidLoad: 然后在viewDidLoad中实现:
// setup location manager
if ([CLLocationManager locationServicesEnabled]) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.delegate = self;
[_locationManager startUpdatingLocation];
}
And you need to implement the delegate: 并且您需要实现委托:
locationManager:didUpdateLocations:
Be careful: In IOS 7 注意:在IOS 7中
locationManager:didUpdateToLocation:fromLocation
is deprecated. 不推荐使用。 Apple link to CLLocationManagerDelegate
Apple链接到CLLocationManagerDelegate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.