I just have a quick question regarding app life cycles and programming in Swift. I am trying to return to home screen whenever a user goes to the background. For instance, if a user receives a call or push home button, the app should go back to the main screen it started from instead of where it left off.
func applicationWillEnterForeground(_ application: UIApplication) {
guard let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(
withIdentifier: "main") as? MainViewController else { return }
self.window?.rootViewController?.present(vc, animated: true, completion: nil)
}
Above is the code I have in appDelegate, but somehow it gives an error: Attempt to present ... on ... whose view is not in the window hierarchy!"
Please help me out. Thank you very much!!