5

I am experiencing some strange behavior in my app. Sometimes, when users kill the app, SceneDelegate.init() and scene(_:willConnectTo:options:) are called again which causes running the app init flow again. This results in some unexpected behavior and the app crashes.

AppDelegate:

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        return true
    }
...
}

SceneDelegate:

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    override init() {
        super.init()

        print("Init")
    }

    func scene(_ scene: UIScene, willConnectTo _: UISceneSession, options: UIScene.ConnectionOptions) {
        guard let scene = (scene as? UIWindowScene) else {
            return
        }

        print("App starting")

        ...
    }
}

My stack trace looks like this (after killing the app): stack trace

Could it be some bug in the iOS, or there is something wrong on my side?

Thank you.

Tomáš Černý
  • 101
  • 1
  • 6

0 Answers0