iOS 13 isKeyWindow always returns nil

602 views Asked by At

I am wondering why:

UIApplication.shared.windows.first { $0.isKeyWindow } 

always returns nil both in the simulator and on device. You can confirm this by putting a break point in viewDidLoad in any view controller and printing the object to the console.

po UIApplication.shared.windows.first { $0.isKeyWindow } 

The only way I can get the "keyWindow" is by getting

UIApplication.shared.windows.first

But there is no explicit mention that it is key. What if there are multiple instances of my app on iPad Split view?

Any ideas?

My thinking is, if there is only one window it's key by default and if you're running more than one window on iPad the one that is currently being interacted with will become the key window, however, I haven't tested this.

1

There are 1 answers

1
Boris On

Have you tried this?

UIApplication.shared.windows.filter {$0.isKeyWindow}.first