我可以在 iOS 应用程序的任何部分检查当前是否显示 UIAlertView 吗?我找到了这段代码
[NSClassFromString(@"_UIAlertManager") performSelector:@selector(topMostAlert)]
但它是私有 API,我的应用程序可能会被 Apple 拒绝。
有没有合法的方法可以做到这一点?
对于低于 iOS 7 的设备:-
当你制作身体时UIAlertView
, the [alertView Show]
在主窗口上添加子视图。所以要检测到UIAlertView
您只需检查当前的子视图UIView
as 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)];
and
UIAlertView *Alert = [NSClassFromString(@"_UIAlertManager") performSelector:@selector(Alert)];
NOTE :-如果您无法使用第三方 API,那么您在 iOS7 中唯一真正的选择就是实际跟踪您的警报视图。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)