I came across a similar situation, but instead of hiding, I wanted to show a block code screen to provide access. In any case, I think the solution also applies to your needs.
I often implement a custom base view controller in iOS apps. Therefore, instead of dealing with applicationDidBecomeActive:
or applicationWillResignActive:
I configure this view controller to listen for equivalent notifications:
@interface BaseViewController : UIViewController - (void)prepareForGrantingAccessWithNotification:(NSNotification *)notification; - (void)grantAccessWithNotification:(NSNotification *)notification; @end @implementation BaseViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self addNotificationHandler:@selector(grantAccessWithNotification:) forNotification:UIApplicationDidBecomeActiveNotification]; [self addNotificationHandler:@selector(prepareForGrantingAccessWithNotification:) forNotification:UIApplicationWillResignActiveNotification]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)prepareForGrantingAccessWithNotification:(NSNotification *)notification { // Hide your views here myCustomView.alpha = 0; // Or in my case, hide everything on the screen self.view.alpha = 0; self.navigationController.navigationBar.alpha = 0; } - (void)grantAccessWithNotification:(NSNotification *)notification { // This is only necessary in my case [self presentBlockCodeScreen]; self.view.alpha = 1; self.navigationController.navigationBar.alpha = 1; ... } @end
source share