// // AppDelegate+ThirdConfig.m // YUMI // // Created by YUMI on 2021/9/13. // #import "AppDelegate+ThirdConfig.h" ///Third #import #import #import ///Tool #import "YUMIConstant.h" #import "CustomAttachmentDecoder.h" #import "QEmotionHelper.h" #import "XPAdvertiseView.h" #import "XPAdImageTool.h" #import "YUMIMacroUitls.h" #import "AdvertiseModel.h" #import "XPWebViewController.h" #import "XPRoomViewController.h" #import "XCCurrentVCStackManager.h" #import "ClientConfig.h" UIKIT_EXTERN NSString * kYouMiNumberCountKey; UIKIT_EXTERN NSString * adImageName; @implementation AppDelegate (ThirdConfig) /// 初始化一些第三方配置 - (void)initThirdConfig { [self configShareSDK]; [self configNIMSDK]; [self initEmojiData]; } - (void)configNIMSDK { //推荐在程序启动的时候初始化 NIMSDK NSString *appKey = KeyWithType(KeyType_NetEase); NIMSDKOption *option = [NIMSDKOption optionWithAppKey:appKey]; [[NIMSDK sharedSDK] registerWithOption:option]; // NIM SDK初始化 [NIMCustomObject registerCustomDecoder:[[CustomAttachmentDecoder alloc] init]]; [NIMSDKConfig sharedConfig].shouldConsiderRevokedMessageUnreadCount = YES; ///置顶会话同步 [[NIMSDKConfig sharedConfig] setShouldSyncStickTopSessionInfos:YES]; #ifdef DEBUG [NIMSDKConfig sharedConfig].enabledHttpsForInfo = NO; [NIMSDKConfig sharedConfig].enabledHttpsForMessage = NO; #endif } - (void)configShareSDK { [ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) { ///faceBook [platformsRegister setupFacebookWithAppkey:@"1266232494209868" appSecret:@"c9b170b383f8be9cdf118823b8632821" displayName:YMLocalizedString(@"AppDelegate_ThirdConfig0")]; [platformsRegister setupLineAuthType:SSDKAuthorizeTypeBoth]; }]; } #pragma mark - 表情 - (void)initEmojiData { NSArray * dicArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"emoji" ofType:@"plist"]]; NSDictionary * dic = [dicArray firstObject]; NSArray * emojiArray = dic[@"data"]; NSMutableArray * array = [NSMutableArray array]; for (int i = 0; i < emojiArray.count; i++) { NSDictionary * dic = [emojiArray objectAtIndex:i]; UIImage * image = [UIImage imageNamed:dic[@"file"]]; QEmotion * info = [[QEmotion alloc] init]; info.identifier = dic[@"id"]; info.image = image; info.displayName = dic[@"tag"]; [array addObject:info]; } //在这里强烈建议先预加载一下表情 QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper]; faceManager.emotionArray = array; } #pragma mark - 广告 /** 设置广告页 */ - (void)setupLaunchADView { NSUserDefaults * kUserDefaults = NSUserDefaults.standardUserDefaults; // 判断沙盒中是否存在广告图片,如果存在,直接显示 NSString *filePath = [XPAdImageTool.shareImageTool getFilePathWithImageName:[kUserDefaults valueForKey:adImageName]]; BOOL isExist = [XPAdImageTool.shareImageTool isFileExistWithFilePath:filePath]; NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; if ([userDefault integerForKey:@"adShow"]) { [userDefault setInteger:[userDefault integerForKey:@"adShow"]+1 forKey:@"adShow"]; } else { [userDefault setInteger:1 forKey:@"adShow"]; } if (isExist) {// 图片存在 if ([userDefault integerForKey:@"adShow"] > 4) { @kWeakify(self); NSString *imageName = [kUserDefaults valueForKey:adImageName]; AdvertiseModel *info = [XPAdImageTool.shareImageTool getAdInfoFromCacheInMainWith:imageName]; XPAdvertiseView *advertiseView = [[XPAdvertiseView alloc] initWithFrame:self.window.bounds]; advertiseView.filePath = filePath; advertiseView.dismissHandler = ^(BOOL shouldJump) { @kStrongify(self) if (!shouldJump || info == nil) { return; } [self performSelectorOnMainThread:@selector(advertiseJumpHandleWithInfo:) withObject:info waitUntilDone:NO]; }; [advertiseView show]; } } } /// 闪屏广告跳转处理 - (void)advertiseJumpHandleWithInfo:(AdvertiseModel *)info { if (![ClientConfig shareConfig].canOpen) { return; } if (UIApplication.sharedApplication.keyWindow != self.window) { //当前窗口不是主控制器所在窗口时,拦截跳转(目前可能情况时,闪屏后出现新人引导 return; } switch (info.type) { case SplashInfoSkipTypeRoom: { if (![[XPAdImageTool shareImageTool] isImLogin]) { return; // 必须登录后才可以跳转 } // 跳转房间 if (info.link.length > 0) { [XPRoomViewController openRoom:info.link viewController:[XCCurrentVCStackManager shareManager].getCurrentVC]; } } break; case SplashInfoSkipTypeWeb: { // 跳转 H5 if (info.link.length > 0) { XPWebViewController *webView = [[XPWebViewController alloc]init]; webView.url = info.link; [[[XCCurrentVCStackManager shareManager]currentNavigationController] pushViewController:webView animated:YES]; } } break; default: break; } } @end