Get Application's main window

Jonathan. picture Jonathan. · Jul 24, 2013 · Viewed 39.2k times · Source

UIApplication has a method keyWindow, however if an alert view is showing then this returns the window of the alert view and not the main window of the application.

How can I get the app's main window?

Answer

Espresso picture Espresso · Jul 24, 2013

The UIApplicationDelegate usually has a reference to the "main window":

[[[UIApplication sharedApplication] delegate] window];

Furthermore, UIApplication has an array of windows [[UIApplication sharedApplication] windows].

See the UIApplication Class Reference.