简体   繁体   中英

iOS 7 Significant location change launch after termination

My app automatically wakes up after termination when new location data arrives on iOS 6, but not on iOS 7.

[[UIApplication sharedApplication] setBackgroundRefreshStatus] is UIBackgroundRefreshStatusAvailable .

In Info.plist I set UIBackgroundModes with value "location".

CLLocationManager started this way:

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

Does anybody know where is a problem?

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

不建议使用locationManager:didUpdateToLocation:fromLocation:方法,从iOS 6开始生效。您现在应该使用locationManager:didUpdateLocations:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM