For devices less than iOS 7 :-
When you make the body of the UIAlertView
, the [alertView Show]
adds a subview on the main window. So to detect the UIAlertView
you simply have to check for the subviews of the current UIView
as UIAlertView
inherits from UIView
.
for (UIWindow* window in [UIApplication sharedApplication].windows){
for (UIView *subView in [window subviews]){
if ([subView isKindOfClass:[UIAlertView class]]) {
NSLog(@"AlertView is Present");
}else {
NSLog(@"AlertView Not Available");
}
}
}
EDIT:- For devices using iOS 7
Class UIAlertManager = objc_getClass("_UIAlertManager");
UIAlertView *Alert = [UIAlertManager performSelector:@selector(Alert)];
and
UIAlertView *Alert = [NSClassFromString(@"_UIAlertManager") performSelector:@selector(Alert)];
NOTE :- If you cannot use third party API's then your only real option in iOS7 is to actually keep track of your alert views.