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
For Swift 5:
var keyWindow: UIWindow? { return UIApplication.shared.connectedScenes.filter({$0.activationState == .foregroundActive}).map({$0 as? UIWindowScene}).compactMap({$0}).first?.windows.filter({$0.isKeyWindow}).first }