Only check for updates when the app becomes active and was actually in the background previously

This commit is contained in:
Andreas Linde 2013-09-24 17:24:45 +02:00
parent aff8c0a9a9
commit bc9ee21078

View File

@ -60,7 +60,8 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
BOOL _sendUsageData;
BOOL _didSetupDidBecomeActiveNotifications;
BOOL _didEnterBackgroundState;
BOOL _firstStartAfterInstall;
NSNumber *_versionID;
@ -89,6 +90,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
- (void)didBecomeActiveActions {
if ([self isUpdateManagerDisabled]) return;
if (!_didEnterBackgroundState) return;
[self checkExpiryDateReached];
if ([self expiryDateReached]) return;
@ -99,9 +101,18 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
}
}
- (void)didEnterBackgroundActions {
_didEnterBackgroundState = NO;
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
_didEnterBackgroundState = YES;
}
}
- (void)setupDidBecomeActiveNotifications {
if (!_didSetupDidBecomeActiveNotifications) {
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(didEnterBackgroundActions) name:UIApplicationDidEnterBackgroundNotification object:nil];
[dnc addObserver:self selector:@selector(didBecomeActiveActions) name:UIApplicationDidBecomeActiveNotification object:nil];
[dnc addObserver:self selector:@selector(didBecomeActiveActions) name:BITHockeyNetworkDidBecomeReachableNotification object:nil];
_installationIdentification = [self stringValueFromKeychainForKey:kBITUpdateInstallationIdentification];
@ -112,6 +123,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
- (void)cleanupDidBecomeActiveNotifications {
[[NSNotificationCenter defaultCenter] removeObserver:self name:BITHockeyNetworkDidBecomeReachableNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
}