Fixed self.validated not always being set to NO if restrictionEnforcementFrequency is set to BITAuthenticatorAppRestrictionEnforcementOnAppActive

This commit is contained in:
Andreas Linde
2013-12-04 14:08:08 +01:00
parent 785f654060
commit 6d6012b0f6
2 changed files with 11 additions and 14 deletions

View File

@@ -48,7 +48,7 @@ static NSString* const kBITAuthenticatorAuthTokenTypeKey = @"BITAuthenticatorAut
@implementation BITAuthenticator { @implementation BITAuthenticator {
id _appDidBecomeActiveObserver; id _appDidBecomeActiveObserver;
id _appWillResignActiveObserver; id _appDidEnterBackgroundOberser;
UIViewController *_authenticationController; UIViewController *_authenticationController;
BOOL _isSetup; BOOL _isSetup;
@@ -651,13 +651,13 @@ static NSString* const kBITAuthenticatorAuthTokenTypeKey = @"BITAuthenticatorAut
[strongSelf applicationDidBecomeActive:note]; [strongSelf applicationDidBecomeActive:note];
}]; }];
} }
if(nil == _appWillResignActiveObserver) { if(nil == _appDidEnterBackgroundOberser) {
_appWillResignActiveObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillResignActiveNotification _appDidEnterBackgroundOberser = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidEnterBackgroundNotification
object:nil object:nil
queue:NSOperationQueue.mainQueue queue:NSOperationQueue.mainQueue
usingBlock:^(NSNotification *note) { usingBlock:^(NSNotification *note) {
typeof(self) strongSelf = weakSelf; typeof(self) strongSelf = weakSelf;
[strongSelf applicationWillResignActive:note]; [strongSelf applicationDidEnterBackground:note];
}]; }];
} }
} }
@@ -667,9 +667,9 @@ static NSString* const kBITAuthenticatorAuthTokenTypeKey = @"BITAuthenticatorAut
[[NSNotificationCenter defaultCenter] removeObserver:_appDidBecomeActiveObserver]; [[NSNotificationCenter defaultCenter] removeObserver:_appDidBecomeActiveObserver];
_appDidBecomeActiveObserver = nil; _appDidBecomeActiveObserver = nil;
} }
if(_appWillResignActiveObserver) { if(_appDidEnterBackgroundOberser) {
[[NSNotificationCenter defaultCenter] removeObserver:_appWillResignActiveObserver]; [[NSNotificationCenter defaultCenter] removeObserver:_appDidEnterBackgroundOberser];
_appWillResignActiveObserver = nil; _appDidEnterBackgroundOberser = nil;
} }
} }
@@ -755,11 +755,8 @@ static NSString* const kBITAuthenticatorAuthTokenTypeKey = @"BITAuthenticatorAut
[self authenticate]; [self authenticate];
} }
- (void)applicationWillResignActive:(NSNotification *)note { - (void)applicationDidEnterBackground:(NSNotification *)note {
//only reset if app is really going into the background, e.g not when pulling down if(BITAuthenticatorAppRestrictionEnforcementOnAppActive == self.restrictionEnforcementFrequency) {
//the notification center
if(BITAuthenticatorAppRestrictionEnforcementOnAppActive == self.restrictionEnforcementFrequency &&
[[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
self.validated = NO; self.validated = NO;
} }
} }

View File

@@ -60,11 +60,11 @@
@property (nonatomic, copy, readonly) NSString *installationIdentifier; @property (nonatomic, copy, readonly) NSString *installationIdentifier;
/** /**
* method registered as observer for applicationWillBecomeInactive events * method registered as observer for applicationDidEnterBackground events
* *
* @param note NSNotification * @param note NSNotification
*/ */
- (void) applicationWillResignActive:(NSNotification*) note; - (void) applicationDidEnterBackground:(NSNotification*) note;
/** /**
* method registered as observer for applicationsDidBecomeActive events * method registered as observer for applicationsDidBecomeActive events