diff options
author | Jesse Bounds <jesse@rebounds.net> | 2017-02-27 12:03:10 -0800 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2017-03-01 08:25:44 -0800 |
commit | 0027f5cdc2c266695ca86d441ab694366820b664 (patch) | |
tree | d6d1fb8f4e974993540c3a3d0bf399c809bd12bc | |
parent | e1546644b55dab8ea0171f415fe491ae21d5d89b (diff) | |
download | qtlocation-mapboxgl-0027f5cdc2c266695ca86d441ab694366820b664.tar.gz |
[ios] Pause file source activity on background
This uses the pause/resume API on the default file source to pause
network and revalidation activity when the host iOS application goes
into the background. Activity is resumed when the host application goes
into the foreground.
The intention of this change is to avoid edge cases on some OSs where
resources (i.e. sqlite) are not available when the host app is not
visible to the user.
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage.mm | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm index 64f9111f14..9cb472ce5d 100644 --- a/platform/darwin/src/MGLOfflineStorage.mm +++ b/platform/darwin/src/MGLOfflineStorage.mm @@ -40,12 +40,26 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = MGLOfflinePackUserInfoK static MGLOfflineStorage *sharedOfflineStorage; dispatch_once(&onceToken, ^{ sharedOfflineStorage = [[self alloc] init]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[NSNotificationCenter defaultCenter] addObserver:sharedOfflineStorage selector:@selector(unpauseFileSource:) name:UIApplicationWillEnterForegroundNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:sharedOfflineStorage selector:@selector(pauseFileSource:) name:UIApplicationDidEnterBackgroundNotification object:nil]; +#endif [sharedOfflineStorage reloadPacks]; }); return sharedOfflineStorage; } +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +- (void)pauseFileSource:(__unused NSNotification *)notification { + _mbglFileSource->pause(); +} + +- (void)unpauseFileSource:(__unused NSNotification *)notification { + _mbglFileSource->resume(); +} +#endif + - (void)setDelegate:(id<MGLOfflineStorageDelegate>)newValue { _delegate = newValue; if ([self.delegate respondsToSelector:@selector(offlineStorage:URLForResourceOfKind:withURL:)]) { @@ -203,6 +217,7 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = MGLOfflinePackUserInfoK } - (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; [[MGLNetworkConfiguration sharedManager] removeObserver:self forKeyPath:@"apiBaseURL"]; [[MGLAccountManager sharedManager] removeObserver:self forKeyPath:@"accessToken"]; |