View a specific view controller from AppDelegate

I am trying to present a view controller (kind of requesting a password) every time my application becomes active. Once the correct password is entered, it should pop out of the stack. The access code I’m trying to click is not the initial view controller, so it’s hard for me to access it from the AppDelegate applicationDidBecomeActive.

I also tried to click the access code view from my MainViewController ViewWillAppear, but it is not called when the application becomes active; only when the screen is updated.

I have been studying similar issues through SO in the last couple of days, but I still don't understand the correct method. I heard that maybe I can’t do it this way because applicationDidBecomeActive can be called before the Storyboard or NavigationController is connected / initialized / etc.

If someone could provide me with the correct way to click / submit a presentation, or if it would be better somewhere else to do such things, I would appreciate it.

Solved : I just deleted the view from the storyboard and used the tip instead. I used:

PasscodeUnlockVC *passcodeUnlock = [[PasscodeUnlockVC alloc] initWithNibName:@"PasscodeUnlockVC" bundle:[NSBundle mainBundle]]; [(UINavigationController *)self.window.rootViewController pushViewController:passcodeUnlock animated:NO]; 

View hierarchy data:

 (gdb) po [[(id)UIApp keyWindow] recursiveDescription] <UIWindow: 0x736a4b0; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x7367b40>> | <UILayoutContainerView: 0x76977a0; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x769de60>> | | <UINavigationTransitionView: 0x7692110; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x769a8c0>> | | | <UIViewControllerWrapperView: 0x73868d0; frame = (0 64; 320 416); autoresize = W+H; layer = <CALayer: 0x75510e0>> | | | | <UIView: 0x76b93e0; frame = (0 0; 320 416); autoresize = W+H; layer = <CALayer: 0x7386850>> | | <UINavigationBar: 0x73664b0; frame = (0 20; 320 44); clipsToBounds = YES; opaque = NO; autoresize = W; layer = <CALayer: 0x7366550>> | | | <UINavigationBarBackground: 0x7360ea0; frame = (0 0; 320 44); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7366520>> - (null) | | | <UINavigationItemView: 0x76b95e0; frame = (160 21; 0 0); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x76aa8e0>> | | | <UINavigationItemButtonView: 0x7550650; frame = (5 7; 73 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7368b40>> Current language: auto; currently objective-c (gdb) 
+7
source share
3 answers

I suggest you use applicationWillEnterForeground: rather than applicationDidBecomeActive: because it works better with multitasking gestures. For example, you do not want to set a lock screen if the user double-clicks the home button to display the taskbar, and then rejects the taskbar without changing applications.

Presumably your AppDelegate has a window property, and you know that your Windows root window controller is a UINavigationController .

 - (void)applicationWillEnterForeground:(UIApplication *)application { PasscodeViewController *pvc = [[PasscodeViewController alloc] init]; [(UINavigationController *)self.window.rootViewController pushViewController:pvc animated:NO]; // [pvc release]; if not using ARC } 
+4
source

Solved

 PasscodeViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"passcodeVCID"]; UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:vc]; navController.navigationBar.hidden = YES; vc.mode = @"enable"; self.window.rootViewController = navController; 

Using the applicationWillEnterForeground method.

0
source

Quick and generalized version:

 getRootViewController().presentViewController(messageVC, animated: true, completion: nil) func getRootViewController() -> UIViewController { return (UIApplication.sharedApplication().delegate?.window??.rootViewController)! } 
0
source

All Articles