Swift - App进入后台时去查看

Swift - Go to view when App enters background

如何让我的应用程序在检测到它进入后台时进入视图?我有一个身份验证屏幕,我希望用户在返回应用程序时必须再次进行身份验证。 (类似于 1password)

我试图在 appDelegate 中做一些事情,但我遇到了很多错误。

let mapViewControllerObejct = self.storyboard?.instantiateViewControllerWithIdentifier("MainVC") as? MainVC
self.navigationController?.pushViewController(mapViewControllerObejct!, animated: false)

这是我尝试在 applicationWillResignActive 中实现的,但我收到错误消息,即 appDelegate 没有名为 storyboard 的成员。

感谢帮助

您可以移动到根视图控制器并在此函数中编写此代码:

func applicationWillEnterForeground(application: UIApplication) {
    if let navigationController = window?.rootViewController as?UINavigationController {
        navigationController.popToRootViewControllerAnimated(false)
    }
}