Envin
Envin

Reputation: 1523

When app enters background, I want to transition back to the first view

When the App enters the background, it logs the person out of the application (per the specifications).

I want to transition back to the first view controller. This is not a navigation or a tab bar controller (although it does transition into those after the first scene).

I tried this in the AppDelegate

- (void)applicationDidEnterBackground:(UIApplication *)application
{
        LoginRegisterViewController *controller = [[LoginRegisterViewController alloc] init];
        [self.window setRootViewController:controller];
}

but it just transitions me to a black screen.

Any suggestions?

Upvotes: 0

Views: 123

Answers (4)

Envin
Envin

Reputation: 1523

This was the only one that worked for me,

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
LoginRegisterViewController *myVC = (LoginRegisterViewController *)[storyboard instantiateInitialViewController];
[self.window setRootViewController:myVC];

in the foreground method.

Upvotes: 0

Ravindra Singh
Ravindra Singh

Reputation: 50

Try This code

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidTimeout:)name:kApplicationDidTimeoutNotification object:nil];

    return YES;

}

  • (void) applicationDidTimeout:(NSNotification *) notif {

    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;

    [navigationController popToRootViewControllerAnimated:YES];

}

  • (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

[[NSNotificationCenter defaultCenter] postNotificationName:kApplicationDidTimeoutNotification object:nil];

}

Sweet & simple coding......

Upvotes: 0

neilco
neilco

Reputation: 8012

Rather than performing the transition on applicationDidEnterBackground: do it in applicationWillEnterForeground:.

Upvotes: 1

simalone
simalone

Reputation: 2768

I think you want something like a locked screen whick will show when enter foreground again. Add a sub UIWindow may be better.

Upvotes: 0

Related Questions