Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Zolotarev <alex@maps.me>2015-06-23 16:18:57 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:52:26 +0300
commite2edf0a7f8c59d09a493035f4668e032bb499a8f (patch)
treec5a0f9902db908cab21400ad5b092f607c9a3a0d /3party/Alohalytics/src/apple/alohalytics_objc.mm
parent77573a493618cb67aa708f51c9fbcffcaea9fa51 (diff)
[alohalytics][ios] Gracefully finish background task before system kills us.
Diffstat (limited to '3party/Alohalytics/src/apple/alohalytics_objc.mm')
-rw-r--r--3party/Alohalytics/src/apple/alohalytics_objc.mm10
1 files changed, 8 insertions, 2 deletions
diff --git a/3party/Alohalytics/src/apple/alohalytics_objc.mm b/3party/Alohalytics/src/apple/alohalytics_objc.mm
index ff95ce02b8..b36a11e4d0 100644
--- a/3party/Alohalytics/src/apple/alohalytics_objc.mm
+++ b/3party/Alohalytics/src/apple/alohalytics_objc.mm
@@ -460,8 +460,14 @@ bool IsConnectionActive() {
Stats::Instance().LogEvent("$applicationDidEnterBackground");
if (IsConnectionActive()) {
- // Start uploading in the background, we have about 10 mins to do that.
- sBackgroundTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ EndBackgroundTask(); }];
+ // Start uploading in the background, but keep in mind, that we have a limited time to do that.
+ // Graceful background task finish is a must before system time limit hits.
+ UIApplication * theApp = [UIApplication sharedApplication];
+ void (^endBackgroundTaskBlock)(void) = ^{ EndBackgroundTask(); };
+ ::dispatch_after(::dispatch_time(DISPATCH_TIME_NOW, static_cast<int64_t>(theApp.backgroundTimeRemaining)),
+ ::dispatch_get_main_queue(),
+ endBackgroundTaskBlock);
+ sBackgroundTaskId = [theApp beginBackgroundTaskWithExpirationHandler:endBackgroundTaskBlock];
alohalytics::Stats::Instance().Upload(&OnUploadFinished);
} else {
if (Stats::Instance().DebugMode()) {