2016-09-20 8 views
0

私は特定の時間間隔でアプリケーションのすべての状態で位置更新を取得する必要があるプロジェクトに取り組んでいます。私はbackgroundとforegroundの特定の時間間隔でlocationUpdateメソッドを呼び出すためにNSTimerを使いました。しかし、タイマーは、インターバル時間が約30秒であれば、バックグラウンドでのみ動作します.300秒にインターバルを増加させると、10分でもバックグラウンドでタイマーが動作しません。私に教えてください - 少なくとも1日はバックグラウンドでタイマーを実行し、300秒程度の時間間隔で実行したり、特定の時間間隔ですべての州で位置更新を取得する方法はありますか?iOSで約300秒の時間間隔で1日か2日間、バックグラウンドでNSTimerを実行するには?

ありがとうございました!

答えて

0

NSTimerをバックグラウンドでのアップデートよりも好む理由はありますか?

// Delegate method from the CLLocationManagerDelegate protocol. 
- (void)locationManager:(CLLocationManager *)manager 
    didUpdateLocations:(NSArray *)locations { 
// Add the new locations to the hike 
[self.hike addLocations:locations]; 

// Defer updates until the user hikes a certain distance 
// or when a certain amount of time has passed. 
if (!self.deferringUpdates) { 
    CLLocationDistance distance = self.hike.goal - self.hike.distance; 
    NSTimeInterval time = [self.nextAudible timeIntervalSinceNow]; 
    [locationManager allowDeferredLocationUpdatesUntilTraveled:distance 
                timeout:time]; 
self.deferringUpdates = YES; 
    } 
} 

https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

+0

私は解決策に到達することができません。少し詳しく教えていただけますか? nextAudible、deferringUpdatesとは何ですか? @eltomato – Kirti

+0

このコードは、コードの下のリンクに記載されています!私はバックグラウンドの場所はあなたが必要とするものだと思う! – eltomato

+0

私はこの方法を使用しましたが、位置の更新は延期されていません!!!! @eltomato – Kirti

関連する問題