2012-10-20 24 views
5

我嘗試使用新的iOS的遞延位置更新6的功能,但不斷收到此錯誤:如何使用延期位置iOS 6?

didFinishDeferredUpdatesWithError:錯誤域= kCLErrorDomain碼= 11「的操作無法完成(kCLErrorDomain錯誤。 11)」

我使用下面的代碼:

- (DeviceAPI *) init 
    { 
    locationManager = [[CLLocationManager alloc] init]; 
    [locationManager setDelegate:self]; 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 
    [locationManager startUpdatingLocation]; 
    [locationManager allowDeferredLocationUpdatesUntilTraveled:(CLLocationDistance)100000  timeout:(NSTimeInterval)100000]; 

    return self; 
} 

callback功能:

- (void)locationManager: (CLLocationManager *) manager 
         didFinishDeferredUpdatesWithError:(NSError *)error 
{ 
    NSLog(@"didFinishDeferredUpdatesWithError :%@", [error description]); 
} 

任何幫助?

+0

錯誤11'kCLErrorDomain'是'kCLErrorDeferredFailed'見文檔[這裏](HTTPS://開發商。 apple.com/library/mac/documentation/CoreLocation/Reference/CoreLocationConstantsRef/index.html#//apple_ref/c/tdef/CLError)。 – Pang

+0

我發現這個尋找iOS 10 http://stackoverflow.com/questions/39498899/deferredlocationupdatesavailable-returns-no-in-ios-10 –

回答

0

您是否在您的info.plist UIBackgroundModes字段中設置了位置?

+0

是的,我有...我也發現[CLLocationManager deferredLocationUpdatesAvailable]返回FALSE。這會發生在ios6模擬器和iPhone 4 IOS6設備上。 – user1762103

0

在我的測試中,我發現延遲更新僅適用於iOS 6.0.1或更高版本,但不適用於6.0。我在2個電話1上進行了測試,其中1個是我更新的,1個是我爲了測試原因而使用了6.0。我相信這就是爲什麼模擬器不起作用的原因,如果你的手機沒有更新,那很可能是爲什麼它不起作用。

另外,還要確保你實施

- 的LocationManager:didUpdateLocations:

,而不是現在已經過時

- 的LocationManager:didUpdateToLocation:fromLocation:

,因爲它是需要使用與延期位置更新。

7

根據蘋果開發者論壇的IOS 6.0 SDK,延期定位的更新只適用:

    對iPhone 5的硬件
  • 運行iOS 6.0或更高版本
  • 所需的精度設置爲kCLLocationAccuracyBest
  • 調用「startUpdatingLocation」方法
  • 等待位置更新以大約每秒1次進入
  • 然後開始推遲更新

參見:https://devforums.apple.com/message/751974#751974

所以聽起來像是你需要iPhone 5的硬件,並等待位置更新,以1Hz進來了。

此外,如另一張海報中提到的,您需要在委託中實現locationManager:didUpdateLocations:方法。

-1

我發現[CLRegion initCircularRegionWithCenter]調用一個框架樣品中這樣描述:

「如果覆蓋的半徑過大,會自動註冊失敗,所以夾住半徑的最大值。「

0

在打電話前allowDeferredLocationUpdatesUntilTraveled:超時:距離過濾器設置爲kCLDistanceFilterNone,那麼它會工作