Rocky
Rocky

Reputation: 289

Xcode - Show a ViewController when the app becomes active (coming back from the background)

I want to show a specific ViewController when the app comes foregrounded from the background.

I am using this method to call a ViewController.

- (void)applicationWillEnterForeground:(UIApplication *)application
{
  [self presentMyViewController];
}

But there is a delay when it comes back from the background. Or in other words, you can see the previous view, then you see the ViewController. I don't want to show the previous view at all.

How can achieve this?

Upvotes: 0

Views: 483

Answers (2)

davidf2281
davidf2281

Reputation: 1328

Hide the old view before the app is backgrounded, in your app delegate's applicationDidEnterBackground: method. This is in fact a mechanism that Apple specifically recommends for privacy reasons here:

Remove sensitive information from views before moving to the background. When an app transitions to the background, the system takes a snapshot of the app’s main window, which it then presents briefly when transitioning your app back to the foreground. Before returning from your applicationDidEnterBackground: method, you should hide or obscure passwords and other sensitive personal information that might be captured as part of the snapshot.

Upvotes: 2

matt
matt

Reputation: 534885

If the app comes to the foreground, it must previously have gone into the background. So call presentMyViewController then, when the app has gone into the background.

Upvotes: 0

Related Questions