Pad*_*van 6 iphone objective-c ipad ios
我可以在iOS应用程序的任何部分检查是否有任何UIAlertView现在显示?我找到了这段代码
[NSClassFromString(@"_UIAlertManager") performSelector:@selector(topMostAlert)]
Run Code Online (Sandbox Code Playgroud)
但它是私有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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑: - 适用于使用iOS 7的设备
Class UIAlertManager = objc_getClass("_UIAlertManager");
UIAlertView *Alert = [UIAlertManager performSelector:@selector(Alert)];
Run Code Online (Sandbox Code Playgroud)
和
UIAlertView *Alert = [NSClassFromString(@"_UIAlertManager") performSelector:@selector(Alert)];
Run Code Online (Sandbox Code Playgroud)
注意: -如果您不能使用第三方API,那么iOS7中唯一真正的选项是实际跟踪您的警报视图.
| 归档时间: |
|
| 查看次数: |
7931 次 |
| 最近记录: |