Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zhangkn/df5f46b732fb01e9d9cf1cdcbfc476e0 to your computer and use it in GitHub Desktop.
Save zhangkn/df5f46b732fb01e9d9cf1cdcbfc476e0 to your computer and use it in GitHub Desktop.
%hook UIAlertController
// @property (nonatomic, readonly) NSArray<UIAlertAction *> *actions;
- (void)viewDidAppear:(BOOL)animated {
%orig;
NSLog(@"sb 弹框 title :%@ message:%@",[self title],[self message]);
if (/* condition */ [[self title] isEqualToString:@"未安装 SIM 卡"])
{
[self dismissViewControllerAnimated:YES completion:nil];
}else if( [[self title] isEqualToString:KNEventNeedConniTunes]){
NSLog(@"delete %@",KNEventNeedConniTunes);
[self dismissViewControllerAnimated:YES completion:nil];// 最好将此代码封装成block, 设置一个全局的字段,用于存储block,key 为对应的title
// 根据title 从存储的block数据中获取对应的block执行,这样将使此方法的代码更精简
}
}
%end
// 优化之后的代码
NSString *AlertHeader = [self title];
NSLog(@"sb 弹框 title :%@ message:%@",AlertHeader,[self message]);
KNKNCFUserNotificationHandler handler = KNGHandlers[AlertHeader];//获取对应的block
if (handler) {// 存在之前定义block就执行
// @{key:value,key:value...}
NSDictionary* dict = @{KNKNCFUserNotificationHandlerUIAlertControllerObjectKey:self};
id res = handler(dict);// 获取block的返回结果, 把自己传递给外界
if (res){
NSLog(@"block res: %@",res);
return ;//返回结果
}
}
return;
@zupu8
Copy link

zupu8 commented Aug 12, 2018

请问下,你那边消除了SB弹窗之后,会出现界面无响应的情况吗?我这边环境是IOS8系统

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment