我目前正在開發其他開發人員的iOS應用程序。該應用程序需要監視位置變化,因爲它需要以低精度(百米)知道用戶位置。之前的位置信息的實現是使用NSTimer
和startUpdatingLocation
完成的。執行是這樣的:使用startMonitoringSignificantLocationChanges和NSTimer提高電池使用率
// Fire each 10 seconds start updating location
self.timerPosition = [NSTimer scheduledTimerWithTimeInterval:ti
target:self
selector:@selector(location)
userInfo:nil
repeats:YES];
[self.timerPosition fire];
地點選擇做這個
// Configure & check location services enabled
...
self.locman.delegate = self;
self.locman.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[self.locman startUpdatingLocation];
然後在外景經理代表
[manager stopUpdatingLocation];
但閱讀蘋果文檔獲取用戶的位置,它似乎用低功耗獲取位置的正確方法是使用startMonitoringSignificantLocationChanges
。
我的問題是,將位置計時器與startMonitoringSignificantLocationChanges
而不是startUpdatingLocation
結合使用是一個很好的決定,或者這是一種無意義的方法?
當應用程序處於後臺時,我不需要獲取位置,但是我想知道當應用程序處於活動狀態時用戶更改了位置。
這是無稽之談。您應該使用significantLocationChanges或RegionMonitoring服務。如果不需要後臺支持,那麼我認爲significantLocationChanges可能是更好的方法 – Lefteris