refactored didBecomeActive notification handling

This commit is contained in:
Stefan Haubold 2012-09-12 23:56:35 +02:00
parent 550bca42c1
commit a577d2fe3b
2 changed files with 20 additions and 16 deletions

View File

@ -94,7 +94,7 @@ typedef enum {
BOOL _isAppStoreEnvironment; BOOL _isAppStoreEnvironment;
BOOL _checkForUpdateOnLaunchOfBitUpdateManager; BOOL _didSetupDidBecomeActiveNotifications;
NSString *_uuid; NSString *_uuid;
} }

View File

@ -77,7 +77,6 @@
@synthesize barStyle = _barStyle; @synthesize barStyle = _barStyle;
@synthesize modalPresentationStyle = _modalPresentationStyle; @synthesize modalPresentationStyle = _modalPresentationStyle;
#pragma mark - private #pragma mark - private
- (void)reportError:(NSError *)error { - (void)reportError:(NSError *)error {
@ -131,12 +130,23 @@
} }
- (void)didBecomeActiveActions { - (void)didBecomeActiveActions {
_checkForUpdateOnLaunchOfBitUpdateManager = YES;
if (![self isUpdateManagerDisabled]) { if (![self isUpdateManagerDisabled]) {
[self checkExpiryDateReached]; [self checkExpiryDateReached];
[self startUsage]; if (![self expiryDateReached]) {
[self checkForUpdate]; [self startUsage];
if (_checkForUpdateOnLaunch) {
[self checkForUpdate];
}
}
}
}
- (void)setupDidBecomeActiveNotifications {
if (!_didSetupDidBecomeActiveNotifications) {
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(didBecomeActiveActions) name:UIApplicationDidBecomeActiveNotification object:nil];
[dnc addObserver:self selector:@selector(didBecomeActiveActions) name:BITHockeyNetworkDidBecomeReachableNotification object:nil];
_didSetupDidBecomeActiveNotifications = YES;
} }
} }
@ -353,7 +363,7 @@
_sendUsageData = YES; _sendUsageData = YES;
_disableUpdateManager = NO; _disableUpdateManager = NO;
_checkForTracker = NO; _checkForTracker = NO;
_checkForUpdateOnLaunchOfBitUpdateManager = NO; _didSetupDidBecomeActiveNotifications = NO;
// set defaults // set defaults
self.showDirectInstallOption = NO; self.showDirectInstallOption = NO;
@ -389,10 +399,7 @@
[self startUsage]; [self startUsage];
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter]; NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(startManager) name:BITHockeyNetworkDidBecomeReachableNotification object:nil];
[dnc addObserver:self selector:@selector(stopUsage) name:UIApplicationWillTerminateNotification object:nil]; [dnc addObserver:self selector:@selector(stopUsage) name:UIApplicationWillTerminateNotification object:nil];
[dnc addObserver:self selector:@selector(didBecomeActiveActions) name:UIApplicationDidBecomeActiveNotification object:nil];
[dnc addObserver:self selector:@selector(stopUsage) name:UIApplicationWillResignActiveNotification object:nil]; [dnc addObserver:self selector:@selector(stopUsage) name:UIApplicationWillResignActiveNotification object:nil];
} }
return self; return self;
@ -918,9 +925,7 @@
} }
} else { } else {
if ([self checkForTracker] || ([self isCheckForUpdateOnLaunch] && [self shouldCheckForUpdates])) { if ([self checkForTracker] || ([self isCheckForUpdateOnLaunch] && [self shouldCheckForUpdates])) {
if (!_checkForUpdateOnLaunchOfBitUpdateManager) { [self performSelector:@selector(checkForUpdate) withObject:nil afterDelay:1.0f];
[self performSelector:@selector(checkForUpdate) withObject:nil afterDelay:1.0f];
}
} }
} }
} else { } else {
@ -928,11 +933,10 @@
// if we are in the app store, make sure not to send usage information in any case for now // if we are in the app store, make sure not to send usage information in any case for now
_sendUsageData = NO; _sendUsageData = NO;
if (!_checkForUpdateOnLaunchOfBitUpdateManager) { [self performSelector:@selector(checkForUpdate) withObject:nil afterDelay:1.0f];
[self performSelector:@selector(checkForUpdate) withObject:nil afterDelay:1.0f];
}
} }
} }
[self setupDidBecomeActiveNotifications];
} }