参见英文答案 > 
 iPhone SDK: check if a UIAlertView is showing10个 
 
> Check if UIView is displaying a UIAlertView3个
我可以在iOS应用程序的任何部分检查是否有任何UIAlertView现在显示?我找到了这段代码
> Check if UIView is displaying a UIAlertView3个
我可以在iOS应用程序的任何部分检查是否有任何UIAlertView现在显示?我找到了这段代码
[NSClassFromString(@"_UIAlertManager") performSelector:@selector(topMostAlert)]
但它是私有API,我的应用程序可能会被Apple拒绝.
有没有合法的方法来做到这一点?
解决方法
 对于低于iOS 7的设备: – 
  
 
        当您创建UIAlertView的主体时,[alertView Show]会在主窗口中添加子视图.因此,要检测UIAlertView,您只需检查当前UIView的子视图,因为UIAlertView继承自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");
        }
    }
} 
 编辑: – 适用于使用iOS 7的设备
Class UIAlertManager = objc_getClass("_UIAlertManager");
UIAlertView *Alert = [UIAlertManager performSelector:@selector(Alert)]; 
 和
UIAlertView *Alert = [NSClassFromString(@"_UIAlertManager") performSelector:@selector(Alert)];
注意: – 如果您不能使用第三方API,那么iOS7中唯一真正的选项是实际跟踪您的警报视图.