Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding new UIWindow to the scene on iOS13

I'm adding new UIWindow to show passcode view controller when the app is entering foreground.

Before iOS 13 in AppDelegate I had property var passcodeWindow = UIWindow(frame: UIScreen.main.bounds) where my rootViewController was the passcode view controller and in applicationWillEnterForeground method I was doing passcodeWindow.makeKeyAndVisible() to place it on the top.

Now when I want to implement the passcode functionality in iOS 13 there is a problem with this approach. I moved it to the sceneWillEnterForeground method in SceneDelegate, but it seems like I can't show passcodeWindow on top of the actual window in this scene.

I do it exactly the same as in AppDelegate and the passcodeWindow is not shown.

The way I do it in sceneWillEnterForeground in AppDelegate and in SceneDelegate:

passcodeWindow.rootViewController = passcodeViewController(type: .unlock)
passcodeWindow.makeKeyAndVisible()

I expect passcodeWindow to show on the top of current window in the scene.

like image 934
Kamil Chmiel Avatar asked Aug 02 '19 09:08

Kamil Chmiel


1 Answers

You can try this:

if #available(iOS 13.0, *) {
    if let currentWindowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
        passcodeWindow.windowScene = currentWindowScene
    }
}
like image 84
RichardLiu Avatar answered Sep 28 '22 03:09

RichardLiu