Some notes on my quest to find the UIAlertView in the view hierarchy:
I tried to loop through all of the [UIApplication sharedApplication].windows
view's recursively but couldn't find anything.
The windows
property of UIApplication
docs states the following:
This property contains the UIWindow objects currently associated with
the app. This list does not include windows created and managed by the
system, such as the window used to display the status bar.
So this made me realize that the UIWindow
where UIAlertView
could be located is not even presented to us.
HOWEVER, there is also a property on UIApplication
called keyWindow
. Upon looping through that, I found private classes that would compose an alert view:
On iOS 7: _UIModalItemHostingWindow
, _UIModalItemAlertContentView
, _UIBackdropEffectView
etc.
On iOS 8: _UIAlertControllerActionView
, _UIAlertControllerShadowedScrollView
, _UIBackdropView
etc.
I could not find the UIAlertView
that I presented, but rather, a bunch of classes that compose it internally. So to answer the original question, you can probably use the keyWindow
property and see if you notice these classes, but your app could get rejected for trying to check for private classes.
For folks using, the newer, UIAlertController
available for iOS 8 could get the reference to it using:
[UIApplication sharedApplication].keyWindow.rootViewController.presentedViewController
.