我可以检查现在是否有任何UIAlertView显示? [英] Can i check if any UIAlertView displaying right now?

查看:120
本文介绍了我可以检查现在是否有任何UIAlertView显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在iOS应用程序的任何部分检查是否有任何UIAlertView现在显示?我发现这段代码

Can I in any part of my iOS application check if any UIAlertView displaying right now? I found this code

[NSClassFromString(@"_UIAlertManager") performSelector:@selector(topMostAlert)]

但它是私有API,我的应用可能被Apple拒绝。
有没有合法的方法可以做到这一点?

but it is private API and my app could be rejected by Apple. Are there any legal ways to do this?

推荐答案

对于低于iOS 7的设备: -

当您制作 UIAlertView 的正文时, [alertView Show ] 在主窗口上添加子视图。因此,要检测 UIAlertView ,您只需检查当前 UIView 的子视图为 UIAlertView 继承自 UIView

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");
        }
    }
}

编辑: - 对于使用iOS 7的设备

Class UIAlertManager = objc_getClass("_UIAlertManager");
UIAlertView *Alert = [UIAlertManager performSelector:@selector(Alert)];

UIAlertView *Alert = [NSClassFromString(@"_UIAlertManager") performSelector:@selector(Alert)];

注意: - 如果您不能使用第三方API,那么您唯一真实的iOS7中的选项是实际跟踪您的警报视图。

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.

这篇关于我可以检查现在是否有任何UIAlertView显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆