Last active
August 12, 2018 03:11
-
-
Save zhangkn/df5f46b732fb01e9d9cf1cdcbfc476e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 优化之后的代码 | |
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
请问下,你那边消除了SB弹窗之后,会出现界面无响应的情况吗?我这边环境是IOS8系统