首页 > 代码库 > 抓取第三方广告弹窗里的控件事件-测试成功
抓取第三方广告弹窗里的控件事件-测试成功
由于应用里面添加了弹窗的广告,但是为.a的库文件,出于好奇想抓取弹窗广告内的控件事件,于是写了如下代码测试,成功!
for (id obj in [[[UIApplicationsharedApplication] keyWindow]subviews])
{
NSLog(@"Class Name[%s]",object_getClassName(obj));
NSString * str = [NSStringstringWithFormat:@"%s",object_getClassName(obj)];
if([str isEqualToString:@"UIView"])
{
for (UIView * vv in [(UIView *)obj subviews])
{
NSLog(@"UIView = %@",vv);
for (UIView * hh in vv.subviews)
{
NSLog(@"UIView的子View = %@",hh);
//通过打印hh得知所要获取的控件有tag值,于是根据tag值抓到对应的控件
if(hh.tag == 1)
{
UIButton * btn = (UIButton *)hh;
NSSet* myActions = [btn allTargets];
NSEnumerator * mm = [myActions objectEnumerator];
for (NSString * ssin mm)
{
NSLog(@"遍历枚举的值: %@",ss);
NSArray * array = [btn actionsForTarget:ssforControlEvent:UIControlEventTouchUpInside];
SEL sel = NSSelectorFromString(array[0]);
//sel 则为要抓取的控件事件
[ssperformSelector:sel];
}
}
}
}
}
}
抓取第三方广告弹窗里的控件事件-测试成功