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
The easiest way to do that is:
in Objective-C
[UIApplication sharedApplication].windows.firstObject
in Swift
UIApplication.shared.windows.first!
Note that this works only if you do not support multiple windows.