I have only one window and I tried
UIWindow* mWindow = [[UIApplication sharedApplication] keyWindow];
but this returned nil.
I also
Your application's key window isn't set until [window makeKeyAndVisible]
gets called in your app delegate. Your UIViewController is probably being loaded from a NIB before this call. This explains why keyWindow
is returning nil.
Luckily, your view controller doesn't need to go through UIApplication to get the window. You can just do:
UIWindow *mWindow = self.view.window;