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

对着背影说爱祢 提交于 2020-01-16 18:35:11

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/16290685/xcode-show-a-viewcontroller-when-the-app-becomes-active-coming-back-from-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!