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

后端 未结 6 1066
北海茫月
北海茫月 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:24

    Now you have more than one window, one for each scene. First, you have to answer which one you need at the moment of usage.

    Probably you want to get the window of the currently active scene then you can use this:

        UIWindow* window = nil;
        if (@available(iOS 13.0, *))
        {
            for (UIWindowScene* wScene in [UIApplication sharedApplication].connectedScenes)
            {
                if (wScene.activationState == UISceneActivationStateForegroundActive)
                {
                    window = wScene.windows.firstObject;
    
                    break;
                }
            }
        }
    

提交回复
热议问题