【发布时间】:2014-04-10 12:09:55
【问题描述】:
我正在开发一个具有位置的应用程序并成功获取坐标,然后我正在调用 web 服务来存储坐标,但是当我使用 ios 7.1 设备时,不会重复调用 didupdatelocation 方法。这是我的代码
if ([CLLocationManager locationServicesEnabled])
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.pausesLocationUpdatesAutomatically=NO;
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
}
还有这个
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive)
{
CLLocationCoordinate2D center;
center.latitude = [[locations objectAtIndex:([locations count]-1)] coordinate].latitude;
center.longitude = [[locations objectAtIndex:([locations count]-1)] coordinate].longitude;
_point = [[MKPointAnnotation alloc] init];
_point.coordinate = center;
if(appDelegate.strVehicleType!=nil)
{
[self checkInternet];
}
NSLog(@"Changed");
[_locationManager stopUpdatingLocation];
}
else
{
CLLocationCoordinate2D center;
center.latitude = [[locations objectAtIndex:([locations count]-1)] coordinate].latitude;
center.longitude = [[locations objectAtIndex:([locations count]-1)] coordinate].longitude;
_point = [[MKPointAnnotation alloc] init];
_point.coordinate = center;
if(appDelegate.strVehicleType!=nil)
{
[self checkInternet];
}
NSLog(@"Location Changed in Background")
;
[_locationManager stopUpdatingLocation];
}
}
我已经尝试了上面的代码,位置在 ios 6 和 ios 7 中重复更新,但在 7.1 中没有更新,所以请任何人知道问题出在哪里?或者他们有什么不同的使用方法。
提前感谢。
【问题讨论】:
-
查看我的 iOS 7 及更高版本的解决方案。 stackoverflow.com/questions/18946881/… Github 有一篇博文和完整的解决方案。
标签: ios cllocationmanager