我使用CLLocationManager获取用户的位置,代码如下:
if([CLLocationManager significantLocationChangeMonitoringAvailable]){
if(locationManager==nil)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startMonitoringSignificantLocationChanges];
}
else {
if(locationManager==nil)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 200.0;
[locationManager startUpdatingLocation];
}
当app lanuched并开始定位时,委托方法didUpdateLocations确实调用了。在我得到坐标后,我停止了位置,代码如下:
if([CLLocationManager significantLocationChangeMonitoringAvailable]){
[locationManager stopMonitoringSignificantLocationChanges];
}
else {
[locationManager stopUpdatingLocation];
}
因为需要做其他任务,我使用上面的代码重新启动位置。然后委托方法(didUpdateLocations)永远不会得到回调。 iOS7和iOS6中存在此问题。我做错了什么?感谢。