// // TUITool+TUIPatch.m // Youth // // Created by mambaxie on 2022/2/21. // #import "TUITool+TUIPatch.h" #import #import "NSObject+BKAssociatedObjects.h" #import "PYAppService.h" @implementation TUITool (TUIPatch) + (void)load { NSError *error; [self jr_swizzleClassMethod:@selector(patch_makeToast:) withClassMethod:@selector(makeToast:) error:&error]; if (error) { NSLog(@"patch TUI error: %@", error); } [self jr_swizzleClassMethod:@selector(patch_makeToastError:msg:) withClassMethod:@selector(makeToastError:msg:) error:&error]; } + (NSArray *)ignoreTipsPrefixes { static NSArray *prefixes = nil; if (!prefixes) { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ prefixes = @[ @"You were removed from the group", @"您已被踢出" ]; }); } return prefixes; } + (void)patch_makeToast:(NSString *)str { BOOL shouldIgnore = NO; for (NSString *prefix in [self ignoreTipsPrefixes]) { if ([str hasPrefix:prefix]) { shouldIgnore = YES; break; } } if (shouldIgnore) { return; } [self patch_makeToast:str]; } + (void)patch_makeToastError:(NSInteger)error msg:(NSString *)msg { if (error >= 120001 && error <= 120099) { if (error == 120010) { [PYAppService showVipAlertWithPath:nil title:nil msg:msg source:@"block_chat_wx"]; }else if(error == 120011){ [PYAppService showVipAlertWithPath:nil title:nil msg:msg source:@"block_chat_se"]; }else{ [PYAppService showVipAlertWithPath:nil title:nil msg:msg source:@"block_chat_unknow"]; } }else if (error >= 120100 && error <= 120199) { [MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) { config.title = @"聊天提示"; if ([msg containsString:@"需要互关/VIP才能聊天才能发送图片和语音"]) { config.message = [msg stringByReplacingOccurrencesOfString:@"互关/" withString:@""]; } else { config.message = msg; } config.otherTitle = @"OK"; }]; }else{ [self patch_makeToastError:error msg:msg]; } } @end