ios – Get the focused/current window among multiple windows – Mac Catalyst


I am working on UIMenuBuilder in Mac Catalyst. Because my app supports multiple scenes with different classes of UISceneDelegate, I need to validate UICommands (func validate(_ command: UICommand)) depending on the focused window. I have been trying a few solution, however no one works.

1.

for scene in UIApplication.shared.connectedScenes.filter({$0.activationState == .foregroundActive}) {
    if let delegate = scene.delegate as? SceneDelegate {
          //...
    } else if let delegate = scene.delegate as? DetailSceneDelegate {
          //...
    }
}

In this case, it turns out that each scene (window) has the state foregroundActive – when windows are visible.

2.

for scene in UIApplication.shared.connectedScenes {
    if let delegate = scene.delegate as? SceneDelegate {
          print("SceneDelegate: ", delegate.window?.isKeyWindow)
    } else if let delegate = scene.delegate as? DetailSceneDelegate {
          print("DetailSceneDelegate: ", delegate.window?.isKeyWindow)
}

Here, the app finds each window as a key one.

Thank you in advance!

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img