In Objective-C in the viewDidLoad method of a UIViewController I do this to get the keyWindow reference in my iOS app:
UIWindow * keyWindow = [[UIApplication sh
Swift 5.1
Works for me
If you are also looking for a way to deal with foreground and background modes you should try this
foreground
background
UIApplication.shared.windows.first(where: { $0.isKeyWindow })
Don't call window in didLoad function call the keyWindow in viewDidAppear function of ViewController