From 6d6012b0f65a43b006f2ad44b7a9062262a8a65d Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Wed, 4 Dec 2013 14:08:08 +0100 Subject: [PATCH] Fixed self.validated not always being set to NO if restrictionEnforcementFrequency is set to BITAuthenticatorAppRestrictionEnforcementOnAppActive --- Classes/BITAuthenticator.m | 21 +++++++++------------ Classes/BITAuthenticator_Private.h | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Classes/BITAuthenticator.m b/Classes/BITAuthenticator.m index c4e4d24c57..3da5a383cf 100644 --- a/Classes/BITAuthenticator.m +++ b/Classes/BITAuthenticator.m @@ -48,7 +48,7 @@ static NSString* const kBITAuthenticatorAuthTokenTypeKey = @"BITAuthenticatorAut @implementation BITAuthenticator { id _appDidBecomeActiveObserver; - id _appWillResignActiveObserver; + id _appDidEnterBackgroundOberser; UIViewController *_authenticationController; BOOL _isSetup; @@ -651,13 +651,13 @@ static NSString* const kBITAuthenticatorAuthTokenTypeKey = @"BITAuthenticatorAut [strongSelf applicationDidBecomeActive:note]; }]; } - if(nil == _appWillResignActiveObserver) { - _appWillResignActiveObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillResignActiveNotification + if(nil == _appDidEnterBackgroundOberser) { + _appDidEnterBackgroundOberser = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) { typeof(self) strongSelf = weakSelf; - [strongSelf applicationWillResignActive:note]; + [strongSelf applicationDidEnterBackground:note]; }]; } } @@ -667,9 +667,9 @@ static NSString* const kBITAuthenticatorAuthTokenTypeKey = @"BITAuthenticatorAut [[NSNotificationCenter defaultCenter] removeObserver:_appDidBecomeActiveObserver]; _appDidBecomeActiveObserver = nil; } - if(_appWillResignActiveObserver) { - [[NSNotificationCenter defaultCenter] removeObserver:_appWillResignActiveObserver]; - _appWillResignActiveObserver = nil; + if(_appDidEnterBackgroundOberser) { + [[NSNotificationCenter defaultCenter] removeObserver:_appDidEnterBackgroundOberser]; + _appDidEnterBackgroundOberser = nil; } } @@ -755,11 +755,8 @@ static NSString* const kBITAuthenticatorAuthTokenTypeKey = @"BITAuthenticatorAut [self authenticate]; } -- (void)applicationWillResignActive:(NSNotification *)note { - //only reset if app is really going into the background, e.g not when pulling down - //the notification center - if(BITAuthenticatorAppRestrictionEnforcementOnAppActive == self.restrictionEnforcementFrequency && - [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) { +- (void)applicationDidEnterBackground:(NSNotification *)note { + if(BITAuthenticatorAppRestrictionEnforcementOnAppActive == self.restrictionEnforcementFrequency) { self.validated = NO; } } diff --git a/Classes/BITAuthenticator_Private.h b/Classes/BITAuthenticator_Private.h index c41134600a..86064cc836 100644 --- a/Classes/BITAuthenticator_Private.h +++ b/Classes/BITAuthenticator_Private.h @@ -60,11 +60,11 @@ @property (nonatomic, copy, readonly) NSString *installationIdentifier; /** - * method registered as observer for applicationWillBecomeInactive events + * method registered as observer for applicationDidEnterBackground events * * @param note NSNotification */ -- (void) applicationWillResignActive:(NSNotification*) note; +- (void) applicationDidEnterBackground:(NSNotification*) note; /** * method registered as observer for applicationsDidBecomeActive events