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:
authorIlya Grechuhin <i.grechuhin@mapswithme.com>2015-07-29 16:12:11 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:58:03 +0300
commit5b1bfb87010ea4d864b0db06413435e200e9b90f (patch)
tree09a68823f401c5de874f8d08dec67d59745a5bb3 /iphone/Maps/Classes/LocalNotificationManager.mm
parent77067b304cae920144407ebc0d77fb4e0adb6ffa (diff)
[ios] Fixed crash in background on fetch completion handler duplicate call.
Diffstat (limited to 'iphone/Maps/Classes/LocalNotificationManager.mm')
-rw-r--r--iphone/Maps/Classes/LocalNotificationManager.mm24
1 files changed, 19 insertions, 5 deletions
diff --git a/iphone/Maps/Classes/LocalNotificationManager.mm b/iphone/Maps/Classes/LocalNotificationManager.mm
index 5eefef9dd1..ddf9ec4e66 100644
--- a/iphone/Maps/Classes/LocalNotificationManager.mm
+++ b/iphone/Maps/Classes/LocalNotificationManager.mm
@@ -239,12 +239,18 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
- (void)showDownloadMapNotificationIfNeeded:(void (^)(UIBackgroundFetchResult))completionHandler
{
- self.downloadMapCompletionHandler = completionHandler;
- self.timer = [NSTimer scheduledTimerWithTimeInterval:25 target:self selector:@selector(timerSelector:) userInfo:nil repeats:NO];
- if ([CLLocationManager locationServicesEnabled])
+ NSTimeInterval const completionTimeIndent = 2.0;
+ NSTimeInterval const backgroundTimeRemaining = UIApplication.sharedApplication.backgroundTimeRemaining - completionTimeIndent;
+ if ([CLLocationManager locationServicesEnabled] && backgroundTimeRemaining > 0.0)
+ {
+ self.downloadMapCompletionHandler = completionHandler;
+ self.timer = [NSTimer scheduledTimerWithTimeInterval:backgroundTimeRemaining target:self selector:@selector(timerSelector:) userInfo:nil repeats:NO];
[self.locationManager startUpdatingLocation];
+ }
else
+ {
completionHandler(UIBackgroundFetchResultFailed);
+ }
}
- (void)markNotificationShowingForIndex:(TIndex)index
@@ -271,7 +277,7 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
{
// Location still was not received but it's time to finish up so system will not kill us.
[self.locationManager stopUpdatingLocation];
- self.downloadMapCompletionHandler(UIBackgroundFetchResultFailed);
+ [self performCompletionHandler:UIBackgroundFetchResultFailed];
}
- (void)downloadCountryWithIndex:(TIndex)index
@@ -301,6 +307,14 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
return TIndex();
}
+- (void)performCompletionHandler:(UIBackgroundFetchResult)result
+{
+ if (!self.downloadMapCompletionHandler)
+ return;
+ self.downloadMapCompletionHandler(result);
+ self.downloadMapCompletionHandler = nil;
+}
+
#pragma mark - Location Manager
- (CLLocationManager *)locationManager
@@ -352,7 +366,7 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
}
}
[[Statistics instance] logEvent:flurryEventName withParameters:@{@"WiFi" : @(onWiFi)}];
- self.downloadMapCompletionHandler(result);
+ [self performCompletionHandler:result];
}
@end