0

I have successfully configured google sign in my iOS App using Firebase. After a successful login, I need to make the UIViewController move to HomeViewController. The AppDelegate class has "didSignInFor" method in which I have added the following code

let storyboard = UIStoryboard(name: "Main", bundle: nil)
               let initialViewController = storyboard.instantiateViewController(withIdentifier: "HomeVC")
               self.window?.rootViewController = initialViewController
               self.window?.makeKeyAndVisible()

HomeVC is a storyboard id of HomeViewController and restoration id is also same. But still, it doesn't take me to HomeViewController. I have referred this stack overflow posts.

Opening view controller from app delegate using swift

Please tell me where I am going wrong. I have referred this video for building the app. https://www.youtube.com/watch?v=20Qlho0G3YQ

Here's my AppDelegate.swift file https://pastebin.com/WfzhYAKH

Gunesh Shanbhag
  • 559
  • 5
  • 13

1 Answers1

0

Try:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "HomeVC")
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()

This works for me.

Please comment if you have any questions. Happy to Help!

Mohit Kumar
  • 2,898
  • 3
  • 21
  • 34
  • I have the same code in my AppDelegate file. But it doesn't work. Some doubts I have: 1 DO we need to use navigation controller for the root controller to move to Home controller? – Gunesh Shanbhag May 16 '20 at 06:29
  • I have added this 1 line "self.window = UIWindow(frame: UIScreen.main.bounds)" ..... And no we don't need a navigation controller – Mohit Kumar May 16 '20 at 06:43
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/213985/discussion-between-mohit-kumar-and-gunesh-shanbhag). – Mohit Kumar May 16 '20 at 07:22