iOS 7终止后重大位置更改发布

时间:2013-09-27 10:28:37

标签: ios ios7

我的应用会在新的位置数据到达iOS 6后终止后自动唤醒,但不会在iOS 7上。

[[UIApplication sharedApplication] setBackgroundRefreshStatus]UIBackgroundRefreshStatusAvailable

Info.plist我设置UIBackgroundModes的值为“location”。

CLLocationManager以这种方式开始:

- (void) start {
  if (locationManaher == nil) {
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate        = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
  }

  [locationManager startMonitoringSignificantLocationChanges]
}

- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

  CLLocationCoordinate2D newCoordinate = newLocation.coordinate;
  CLLocationCoordinate2D oldCoordinate = oldLocation.coordinate;

  if (newCoordinate.latitude == oldCoordinate.latitude && newCoordinate.longitude == oldCoordinate.longitude) return;

  float distance = [newLocation distanceFromLocation:oldLocation];

  if (distance < distanceFilter) {
    //send to server 
  }
}

有人知道问题出在哪里吗?

2 个答案:

答案 0 :(得分:4)

这是7.0 iOS功能,如果用户手动关闭应用程序(从主页按钮双击),应用程序不会在位置更改时触发。

答案 1 :(得分:1)

不推荐使用locationManager:didUpdateToLocation:fromLocation:方法,有效的iOS 6.您应该立即使用locationManager:didUpdateLocations: