0

For the new user I have several onboarding screens (all of them are in the same OnboardViewController). If user is successfully registered, I'd change the root controller of my app from OnboardViewController to PreLoadViewController:

let mcVC = PreLoadController()
appDelegateTemp.window?.rootViewController = mcVC

I'm using this controller to display progress of the content loading. After the content is loaded, I'm changing the root controller once again:

if let appDelegateTemp = UIApplication.shared.delegate as? AppDelegate {
        let mcVC = MainViewController()
        let navy = UINavigationController(rootViewController: mcVC)
        appDelegateTemp.window?.rootViewController = navy
}

It works, but I have a very strange bug. When I'm trying to change settings (like, mic settings or notifications settings) from the app, I have to go to iPhone settings:

if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
     UIApplication.shared.open(settingsUrl)
}

But when I'm back I'm shown the OnboardViewController again as if appDelegate doesn't remember that current root controller is mcVC (or, rather, UINavigationController with embed mcVC).

So, why is that, and what is the right way to fix this?

lithium
  • 1,202
  • 12
  • 24
  • When you change settings on Device Settings app, app would be terminated in some cases(like changing privacy setting as show in https://stackoverflow.com/questions/12522574/toggling-privacy-settings-will-kill-the-app). So It seems the app relaunching again.. – Natarajan Nov 07 '18 at 14:42
  • use can try to store some value lets say `currentViewController` in `UserDefaults` and check in `appDelegate` which controller to present – Vlad Nov 07 '18 at 15:09
  • 1
    No, @Natarajan is right, it's just an inevitable crash after changing some settings, it just wasn't obvious to me from simulator. – lithium Nov 07 '18 at 15:13

0 Answers0