How get current keywindow equivalent for multi window SceneDelegate Xcode 11?

后端 未结 6 1092
北海茫月
北海茫月 2020-12-31 22:33

I\'m converting my iOS13 app for iPadOS to SceneDelegate (multi window).

How can I get the current UIWindow from the current SceneDelegate?

I know that a can

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-31 23:03

    You'll want to simply iterate through all your windows and find the key window manually.

    for (UIWindow *window in [UIApplication sharedApplication].windows) {
        if (window.isKeyWindow) {
            // you have the key window
            break;
        }
    }
    

    DO NOT use UISceneActivationStateForegroundActive as the check. That means something different and folks are introducing bugs by using logic to find the first UISceneActivationStateForegroundActive window scene.

提交回复
热议问题