1

当新的位置数据到达 iOS 6 而不是 iOS 7 时,我的应用程序会在终止后自动唤醒。

[[UIApplication sharedApplication] setBackgroundRefreshStatus]UIBackgroundRefreshStatusAvailable

Info.plist我设置UIBackgroundModes值“位置”。

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 
  }
}

有谁知道哪里出了问题?

4

2 回答 2

4

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

于 2013-11-04T08:43:42.947 回答
1

locationManager:didUpdateToLocation:fromLocation:方法已弃用,iOS 6 有效。您应该使用 now locationManager:didUpdateLocations:

于 2013-09-27T11:27:40.163 回答