簡體   English   中英

終止后啟動iOS 7重大位置更改

[英]iOS 7 Significant location change launch after termination

當新的位置數據到達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 
  }
}

有人知道哪里有問題嗎?

這是7.0 iOS功能,如果用戶手動關閉應用程序(通過主頁按鈕雙擊),則該應用程序不會在位置更改時觸發。

不建議使用locationManager:didUpdateToLocation:fromLocation:方法,從iOS 6開始生效。您現在應該使用locationManager:didUpdateLocations:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM