2012-05-30 63 views
1

我的應用程序使用啓動CLLocationManager的典型模式,然後在newLocation足夠準確的情況下從locationManager:didUpdateToLocation:fromLocation:調用stopUpdatingLocation。我的問題是我是否也需要致電我應該在locationManager中發送[locationManager stopUpdatingLocation]:didFailWithError :?

[locationManager stopUpdatingLocation]; 

in locationManager:didFailWithError:。蘋果的文檔說

If the location service is unable to retrieve a location right away, it reports a kCLErrorLocationUnknown error and keeps trying. In such a situation, you can simply ignore the error and wait for a new event.

If the user denies your application’s use of the location service, this method reports a kCLErrorDenied error. Upon receiving such an error, you should stop the location service.

在前者的情況下,我不應該叫stopUpdatingLocation,因爲外景經理仍然可以發出一個很好的位置。其他情況呢?在嘗試使用位置服務之前,我的應用始終檢查[CLLocationManager locationServicesEnabled][CLLocationManager authorizationStatus],所以我真的需要處理kCLErrorDenied的情況嗎?如果發生任何其他錯誤,位置服務是否會自動停止?

回答

0

首先,我認爲你應該處理大多數錯誤情況。特別是如果它像這個一樣容易處理。 ;-)
如果用戶已授予訪問權限並使用您的應用程序,會發生什麼情況。在應用程序運行時,她執行多任務並更改settings.app以禁用位置服務;通常或專門爲您的應用程序。然後,您已經檢查過授權並使用位置更新,但突然之間您再也沒有被授權。我想你就是這麼想的,對吧?