UIApplication sharedApplication - keyWindow is nil?
This code was executed before [window makeKeyAndVisible];
which is inside the app delegate.
So, no wonder why keyWindow
was nil
yet.
Easiest way is to get the window from the app delegate instead:
UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
// Do something with the window now