MOMainTabController.m 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. //
  2. // MOMainTabController.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/10/10.
  6. //
  7. #import "MOMainTabController.h"
  8. #import "MOExploreVC.h"
  9. #import "MOSquareListVC.h"
  10. #import "MOInfomationVC.h"
  11. #import "MOMineVC.h"
  12. #import "MOCreateLiveVC.h"
  13. #import "MOUploadDeviceTool.h"
  14. #import "MOMineSetUpVC.h"
  15. #import "MOShowLivePagesVC.h"
  16. #import "MOTopUpVC.h"
  17. #import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
  18. #import "MONewVersionView.h"
  19. #import "MOTopUpView.h"//充值弹窗
  20. #import "MOBingMobileVC.h"//绑定手机界面
  21. #import "MOWebViewController.h"
  22. #import "MOClickConfigManager.h"
  23. #import "MOActivityCenterVC.h"
  24. #import "UIImage+Color.h"
  25. #if !TARGET_IPHONE_SIMULATOR
  26. #import <Bugly/Bugly.h>
  27. #endif
  28. #import "MOSignInAlertView.h"
  29. #import "MODiamondWinAlertView.h"
  30. #import "MODiaWinVC.h"
  31. #import "MOChatViewController.h"
  32. #import "MOThemeManager.h"
  33. //美颜资源下载
  34. #import "TEDownloader.h"
  35. #import "MOBeautyResDataModels.h"
  36. #import "TEUIConfig.h"
  37. //腾讯IM
  38. #import "TUICore/TUILogin.h"
  39. #import "TIMPush/TIMPush.h"
  40. #import "MOFirstInfoSetVC.h"
  41. #import "MONetAPIClient.h"
  42. #import "MOMainTabController+ChatNotifi.h"
  43. #import "MOCustomTabBarView.h"
  44. #import "MOBeautyDownloadManager.h"
  45. #import "MOVersionModel.h"
  46. #import "MOCustomTabBar.h"
  47. #import <AVFoundation/AVFoundation.h>
  48. static MOMainTabController *_sharedSingleton = nil;
  49. static dispatch_once_t onceToken;
  50. @interface MOMainTabController ()<V2TIMConversationListener,V2TIMSDKListener,V2TIMAdvancedMsgListener, MOCustomTabBarViewDelegate>
  51. @property (nonatomic, strong) MOCustomTabBarView *customTabBarView;
  52. /** */
  53. @property (nonatomic, strong) MOSquareListVC *squareVC;
  54. /** */
  55. @property (nonatomic, strong) MOExploreVC *exploreVC;
  56. /** */
  57. @property (nonatomic, strong) MOInfomationVC *infomationVC;
  58. /** */
  59. @property (nonatomic, strong) MOMineVC *mineVC;
  60. /** 用来表明退出登录短时间只弹出一次 */
  61. @property (nonatomic, assign) BOOL isJustFirstLoginAction;
  62. /** 是否到重新登录界面 */
  63. @property (nonatomic, assign) BOOL isAgainLogin;
  64. /** 无钻石提示view */
  65. @property (nonatomic, strong) MOTitleNormalAlertView *theTipView;
  66. @property (nonatomic, strong) UIViewPropertyAnimator *propertyAnimator;
  67. @property (nonatomic, strong) MONewVersionView *versionView;
  68. @end
  69. @implementation MOMainTabController
  70. + (instancetype)sharedSingleton
  71. {
  72. static dispatch_once_t onceTokenK;
  73. dispatch_once(&onceTokenK, ^
  74. {
  75. // 要使用self来调用
  76. _sharedSingleton = [[self alloc] init];
  77. });
  78. return _sharedSingleton;
  79. }
  80. - (void)viewWillAppear:(BOOL)animated {
  81. [super viewWillAppear:animated];
  82. // 删除系统自动生成的UITabBarButton
  83. for (UIView *child in self.tabBar.subviews) {
  84. if ([child isKindOfClass:[UIControl class]]) {
  85. [child removeFromSuperview];
  86. }
  87. }
  88. }
  89. - (void)viewWillLayoutSubviews {
  90. [super viewWillLayoutSubviews];
  91. // 删除系统自动生成的UITabBarButton
  92. for (UIView *child in self.tabBar.subviews) {
  93. if ([child isKindOfClass:[UIControl class]]) {
  94. [child removeFromSuperview];
  95. }
  96. }
  97. }
  98. - (void)viewDidLoad {
  99. [super viewDidLoad];
  100. [self setupTabbar];
  101. [self addTabbarChildViewControllers];
  102. //AgoraRtcEngineKit 初始化
  103. [[MOShowAgoraKitManager shareManager] prepareEngine];
  104. //美颜License检查, 成功后初始化相应的RTC
  105. // [[MOBeautyDownloadManager shareManager] theXmagicCheckLicense];
  106. [[MOBeautyDownloadManager shareManager] initCacheData];
  107. [[MOBeautyDownloadManager shareManager] setupBeResource];//设置火山美颜资源路径
  108. [[MOBeautyDownloadManager shareManager] toGetTheBytesResCacheArKeyData];//获取火山美颜资源ArKey缓存数据
  109. //进入svga资源获取
  110. [[MOSvgaSourceManage shareManager] loadDictCache];
  111. [[MOSvgaSourceManage shareManager] toGetGiftCategoryListDataAndNeedShowError:NO];
  112. [[MOSvgaSourceManage shareManager] toGetTheWameDataAndNeedShowError:NO];
  113. //刷新管理
  114. [[MORefreshViewManage shareManager] resetAllProperty];
  115. [[MOUploadDeviceTool shareTool] uploadDeviceInfo];
  116. [self addNotification];
  117. self.isJustFirstLoginAction = NO;
  118. self.isAgainLogin = NO;
  119. //webp解码器
  120. SDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];
  121. [[SDImageCodersManager sharedManager] addCoder:webPCoder];
  122. //主题管理器
  123. // [[MOThemeManager shareManager] loadThemeData];
  124. [self setChatNotifiClickBlock];//设置APP内消息点击回调
  125. }
  126. - (void)addNotification{
  127. ReceiveNotification(@selector(againLoginAction:), @"kNotification_AgainLogin")//其他设备登录
  128. ReceiveNotification(@selector(noMoneyTipShow), @"kNotification_NoMoney")//钻石不足
  129. ReceiveNotification(@selector(mayBeShowAlertAction), @"kNotification_FirstShowNoti")//如果有开屏广告页, 则稍后检查相应弹窗
  130. ReceiveNotification(@selector(noBindPhoenTipShow), @"kNotification_NoBindPhone")//没有绑定手机 - 点赞活动
  131. ReceiveNotification(@selector(toCheckTheIMStatus), @"kNotification_CheckTheIMStatus")//检测IM连接状态
  132. ReceiveNotification(@selector(toOpenTheLiveRoom), @"kNotification_OpenTheLiveRoom")//开播
  133. ReceiveNotification(@selector(toCheckAgentJumpRoom), @"kNotification_adjustAgent")
  134. }
  135. - (void)noBindPhoenTipShow{
  136. NSDate *lastTime = [MOTools getTimeOfShowBind];
  137. BOOL needShow = YES;
  138. if(lastTime){
  139. needShow = [MOTools shouldShowAlertWithLastTime:lastTime];
  140. }
  141. if(needShow == NO){
  142. return;
  143. }
  144. //设置显示的时间
  145. [MOTools setTimeOfShowBindDevice:[NSDate date]];
  146. MOTitleNormalAlertView *alertView = [[MOTitleNormalAlertView alloc] init];
  147. alertView.isSingleBtn = YES;
  148. alertView.isStrongBg = YES;
  149. alertView.isShowCloseBtn = YES;
  150. alertView.bgImgView.hidden = YES;
  151. alertView.titleLabel.text = NSLocalString(@"mimo_alert_normal_tip");
  152. alertView.subTitleLabel.text = NSLocalString(@"mimo_alert_no_bind_tip");
  153. [alertView.confirmBtn setTitle:NSLocalString(@"mimo_alert_no_bind_sure_tip") forState:UIControlStateNormal];
  154. alertView.confirmBlock = ^{
  155. MOMainTabController *mainTabbar = [MOMainTabController sharedSingleton];
  156. UINavigationController *nav = mainTabbar.selectedViewController;
  157. if (nav.presentedViewController) {
  158. if ([nav isKindOfClass:[UINavigationController class]]) {
  159. UINavigationController *presentingNavigationController = (UINavigationController *)nav.presentedViewController;
  160. MOBingMobileVC *vc = [[MOBingMobileVC alloc] init];
  161. [presentingNavigationController pushViewController:vc animated:YES];
  162. }
  163. } else {
  164. MOBingMobileVC *vc = [[MOBingMobileVC alloc] init];
  165. [nav pushViewController:vc animated:YES];
  166. }
  167. };
  168. [alertView show];
  169. }
  170. - (void)noMoneyTipShow{
  171. if(self.theTipView){
  172. return;
  173. }
  174. WEAKSELF
  175. self.theTipView = [[MOTitleNormalAlertView alloc] init];
  176. self.theTipView.subTitleLabel.text = NSLocalString(@"mimo_no_money_tip");
  177. [self.theTipView.cancelBtn setTitle:NSLocalString(@"mimo_Cancel") forState:UIControlStateNormal];
  178. [self.theTipView.confirmBtn setTitle:NSLocalString(@"mimo_no_money_jump") forState:UIControlStateNormal];
  179. self.theTipView.isStrongBg = YES;
  180. self.theTipView.confirmBlock = ^{
  181. MOTopUpView *view = [MOTopUpView moTopUpView];
  182. [view showTopUpView];
  183. };
  184. self.theTipView.dismissBlock = ^{
  185. weakSelf.theTipView = nil;
  186. };
  187. [self.theTipView show];
  188. }
  189. - (void)toGetMyLivingRoom{
  190. BOOL isAnchor = GetIsAnchor;
  191. if(isAnchor){
  192. WEAKSELF
  193. [kHttpManager theAnchorGetLiveRoomWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  194. if(kCode_Success){
  195. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  196. MOLiveDetail *dataModel = [MOLiveDetail modelObjectWithDictionary:data[@"data"]];
  197. [weakSelf toCloseTheRoomOrContinueWith:dataModel];
  198. }
  199. else{
  200. MOLogV(@"getGiftHttpDataWith 接口报错了");
  201. }
  202. }];
  203. }
  204. }
  205. - (void)toCloseTheRoomOrContinueWith:(MOLiveDetail *)model{
  206. WEAKSELF
  207. if(model.currentRoom.id.length > 0){
  208. //中心弹窗
  209. MOTitleNormalAlertView *alertView = [[MOTitleNormalAlertView alloc] init];
  210. alertView.subTitleLabel.text = NSLocalString(@"mimo_room_living_open_tip");
  211. [alertView.cancelBtn setTitle:NSLocalString(@"mimo_room_living_close_living") forState:UIControlStateNormal];
  212. [alertView.confirmBtn setTitle:NSLocalString(@"mimo_room_living_continue_living") forState:UIControlStateNormal];
  213. alertView.isStrongBg = YES;
  214. alertView.cancelBlock = ^{
  215. [weakSelf toCloseTheLiveRoomWithRoomId:model.currentRoom.id];
  216. };
  217. alertView.confirmBlock = ^{
  218. [weakSelf toShowRoomWith:model];
  219. };
  220. [alertView show];
  221. }
  222. }
  223. //关闭直播间
  224. - (void)toCloseTheLiveRoomWithRoomId:(NSString *)roomId{
  225. WEAKSELF
  226. NSDictionary *dict = @{@"id":roomId};
  227. [kHttpManager toCloseTheLiveRoomWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  228. MOLogV(@"关闭直播间接口调用");
  229. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_room_end_tip_anchor")];
  230. SendNotification(@"MOSquareListVC_Refresh");
  231. }];
  232. }
  233. - (void)toShowRoomWith:(MOLiveDetail *)model{
  234. BOOL isHaveBeautyRes = [TEDownloader toCheckTheBeautyRes];
  235. if(!isHaveBeautyRes){
  236. [[MOBeautyDownloadManager shareManager] checkAndDownloadBeautyData];
  237. WEAKSELF
  238. [MOBeautyDownloadManager shareManager].progressBlock = ^(CGFloat progress) {
  239. [weakSelf.squareVC updateDownloadBeautyData:progress];
  240. };
  241. [MOBeautyDownloadManager shareManager].completeBlock = ^{
  242. [weakSelf.squareVC downloadBeautyDataSuccess];
  243. };
  244. return;
  245. }
  246. //MARK 检查用户是否对摄像头麦克风授权,未授权不能调用录制功能
  247. AVAuthorizationStatus videoStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  248. AVAuthorizationStatus audioStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
  249. //没有打开摄像头权限
  250. if(videoStatus != AVAuthorizationStatusAuthorized){
  251. [MOCreateLiveVC requestCameraPermissionWithCompletion:^(BOOL open) {
  252. if(!open){
  253. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalString(@"mimo_get_video_authority_fail_tip") message:NSLocalString(@"mimo_get_video_authority_fail_content_tip") delegate:self cancelButtonTitle:NSLocalString(@"mimo_get_video_authority_normal_sure") otherButtonTitles:NSLocalString(@"mimo_get_video_authority_go_sure"), nil];
  254. [alert show];
  255. }
  256. }];
  257. return;
  258. }
  259. //没有打开麦克风权限
  260. if(audioStatus != AVAuthorizationStatusAuthorized){
  261. [MOCreateLiveVC requestAudioPermissionWithCompletion:^(BOOL open) {
  262. if(!open){
  263. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalString(@"mimo_get_audio_authority_fail_tip") message:NSLocalString(@"mimo_get_audio_authority_fail_content_tip") delegate:self cancelButtonTitle:NSLocalString(@"mimo_get_video_authority_normal_sure") otherButtonTitles:NSLocalString(@"mimo_get_video_authority_go_sure"), nil];
  264. [alert show];
  265. }
  266. }];
  267. return;
  268. }
  269. [MOShowAgoraKitManager shareManager].isCreatLive = YES;
  270. MOClickConfigManager *configManager = [MOClickConfigManager shareManager];
  271. configManager.durationTask = model.durationTask;
  272. MOShowLivePagesVC *vc = [[MOShowLivePagesVC alloc] init];
  273. vc.isCreatLive = YES;
  274. vc.userType = MOShowLiveAnchorType;
  275. vc.roomList = @[model.currentRoom].mutableCopy;
  276. vc.liveModel = model;
  277. vc.isNeedSetBeauty = YES;
  278. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  279. nav.modalPresentationStyle = UIModalPresentationFullScreen;
  280. [self presentViewController:nav animated:YES completion:nil];
  281. }
  282. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  283. if (buttonIndex == 1) { // 去设置界面,开启相机访问权限
  284. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  285. }
  286. }
  287. - (void)againLoginAction:(NSNotification *)notification{
  288. WEAKSELF
  289. kMainThreadBlock(^{
  290. if (!weakSelf.isJustFirstLoginAction){
  291. [MOMineSetUpVC toLoginVCAndShowTip:YES];
  292. weakSelf.isJustFirstLoginAction = YES;
  293. weakSelf.isAgainLogin = YES;
  294. [weakSelf performSelector:@selector(changJustFirstLoginAction) withObject:nil afterDelay:2.0];
  295. }
  296. })
  297. }
  298. - (void)changJustFirstLoginAction{
  299. self.isJustFirstLoginAction = NO;
  300. }
  301. - (BOOL)isInLiveRoom {
  302. UINavigationController *nav = self.selectedViewController;
  303. if (nav.presentedViewController) {
  304. if ([nav isKindOfClass:[UINavigationController class]]) {
  305. UINavigationController *presentingNavigationController = (UINavigationController *)nav.presentedViewController;
  306. BOOL isHaveLive = NO;
  307. for (UIViewController *vc in presentingNavigationController.viewControllers) {
  308. if([vc isKindOfClass:[MOShowLivePagesVC class]]){
  309. isHaveLive = YES;
  310. break;
  311. }
  312. }
  313. if(isHaveLive){
  314. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_joined_live_room_tip")];
  315. return YES;
  316. }
  317. }
  318. }
  319. if ([nav isKindOfClass:[UINavigationController class]]) {
  320. BOOL isHaveLive = NO;
  321. for (UIViewController *vc in nav.viewControllers) {
  322. if([vc isKindOfClass:[MOShowLivePagesVC class]]){
  323. isHaveLive = YES;
  324. break;
  325. }
  326. }
  327. if(isHaveLive){
  328. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_joined_live_room_tip")];
  329. return YES;
  330. }
  331. }
  332. return NO;
  333. }
  334. #pragma mark - IM Login
  335. - (void)toLoginIM{
  336. NSString *userNameStirng = GetUserId;
  337. NSString *imToken = GetImToken;
  338. NSString *t_imToken = GetTentImToken;
  339. [self toLoginTheTencentIM];//腾讯IM
  340. [MOTencentSendManage shareManager].myUserId = userNameStirng;
  341. [MOTencentSendManage createCachePath];
  342. }
  343. - (void)toLoginTheTencentIM{
  344. NSString *userNameStirng = GetUserId;
  345. NSString *t_imToken = GetTentImToken;
  346. BOOL isOnlyUseTim = GetOnlyUserTimBool;
  347. BOOL isGetTheTimStatus = [MOTencentSendManage shareManager].isGetTheTimStatus;
  348. //在isOnlyUseTim为NO时, 需要调用一次获取是否启动腾讯IM
  349. if(!isGetTheTimStatus && !isOnlyUseTim){
  350. [MOTencentSendManage shareManager].isGetTheTimStatus = YES;
  351. [self needGetNewTimChatToken];
  352. return;
  353. }
  354. if(t_imToken.length == 0){
  355. //旧版本升级到新版本 - 并不会调用获取TimToken
  356. [self needGetNewTimChatToken];
  357. return;
  358. }
  359. if(userNameStirng.length == 0){
  360. return;
  361. }
  362. if(isOnlyUseTim){
  363. // 添加会话监听器
  364. [[V2TIMManager sharedInstance] removeConversationListener:self];
  365. [[V2TIMManager sharedInstance] addConversationListener:self];
  366. // 添加高级消息监听器
  367. [[V2TIMManager sharedInstance] removeAdvancedMsgListener:self];
  368. [[V2TIMManager sharedInstance] addAdvancedMsgListener:self];
  369. }
  370. [[V2TIMManager sharedInstance] addIMSDKListener:self];
  371. [self toSetTheTencentNormalConfig];//如果使用腾讯IM - 一些通用样式设置
  372. WEAKSELF
  373. [TUILogin login:KTentIMAppID userID:userNameStirng userSig:t_imToken succ:^{
  374. // 获取红点数
  375. MOLogV(@"TUILogin - 成功");
  376. [weakSelf toRegisterTencentPush];
  377. [weakSelf getAllTencentIMUnreadNum];
  378. } fail:^(int code, NSString * _Nullable msg) {
  379. MOLogV(@"TUILogin - 失败");
  380. }];
  381. }
  382. - (void)toRegisterTencentPush{
  383. const int sdkAppId = KTentIMAppID;
  384. NSString *appKey = KTentSDKAppKey;
  385. [TIMPushManager registerPush:sdkAppId appKey:nil succ:^(NSData * _Nonnull deviceToken) {
  386. MOLogV(@"TIMPushManager registerPush success");
  387. } fail:^(int code, NSString * _Nonnull desc) {
  388. MOLogV(@"TIMPushManager registerPush fail code %d desc %@",code,desc);
  389. }];
  390. }
  391. - (void)toSetTheTencentNormalConfig{
  392. [TUIConfig defaultConfig].avatarType = TAvatarTypeRounded;
  393. [TUIConfig defaultConfig].defaultAvatarImage = [UIImage imageNamed:@"icon_mine_placeHolder"];
  394. }
  395. - (void)toCheckTheIMStatus{
  396. WEAKSELF
  397. NSString *token = [NSString stringWithFormat:@"%@",GetToken];
  398. if(token.length == 0){
  399. return;
  400. }
  401. [self toCheckTheTencentIMStatus];//检测腾讯连接
  402. }
  403. - (void)toCheckTheTencentIMStatus{
  404. //腾讯IM没有登录上
  405. if(!TUILogin.isUserLogined){
  406. [self needGetNewTimChatToken];
  407. }
  408. }
  409. - (void)needGetNewTimChatToken{
  410. WEAKSELF
  411. //先执行登出操作
  412. [TUILogin logout:^{
  413. } fail:^(int code, NSString * _Nullable msg) {
  414. }];
  415. //重新获取腾讯登录Token
  416. [kHttpManager toGetChatTokenWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  417. if(kCode_Success){
  418. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  419. NSString *tempStr = [MODataManager objectOrNilForKey:@"tim" fromDictionary:data[@"data"]];
  420. //是否只使用 Tim (腾讯IM)
  421. BOOL isUseTim = [[MODataManager objectOrNilForKey:@"onlyUseTim" fromDictionary:data[@"data"]] boolValue];
  422. [[NSUserDefaults standardUserDefaults] setBool:isUseTim forKey:kOnlyUseTimIM];
  423. if(tempStr.length > 0){
  424. [[NSUserDefaults standardUserDefaults] setObject:tempStr forKey:kTent_ImToken];
  425. [[NSUserDefaults standardUserDefaults] synchronize];
  426. [weakSelf toLoginTheTencentIM];
  427. }
  428. }
  429. else{
  430. MOLogV(@"toGetImTokenWithParams 接口报错了");
  431. }
  432. }];
  433. }
  434. - (void)getAllTencentIMUnreadNum{
  435. BOOL isOnlyUseTim = GetOnlyUserTimBool;
  436. if(isOnlyUseTim){
  437. WEAKSELF
  438. [V2TIMManager.sharedInstance getTotalUnreadMessageCount:^(UInt64 totalUnreadCount) {
  439. [weakSelf updateTheUnreadCountWith:totalUnreadCount];
  440. } fail:^(int code, NSString *desc) {
  441. }];
  442. }
  443. }
  444. #pragma mark - EaseIMKitManagerDelegate
  445. - (void)conversationsUnreadCountUpdate:(NSInteger)unreadCount{
  446. [self updateTheUnreadCountWith:unreadCount];
  447. }
  448. - (void)updateTheUnreadCountWith:(NSInteger)unreadCount{
  449. NSString *badgeStr = @"";
  450. if (unreadCount > 0)
  451. {
  452. if (unreadCount < 100)
  453. {
  454. badgeStr = [NSString stringWithFormat:@"%ld",(long)unreadCount];
  455. }
  456. else
  457. {
  458. badgeStr = @"99+";
  459. }
  460. }
  461. dispatch_async(dispatch_get_main_queue(), ^
  462. {
  463. [self.customTabBarView setIMUnreadMsgCount:badgeStr];
  464. //更新单例里面相应的未读数标记
  465. [MOSvgaSourceManage shareManager].theUserRedNum = unreadCount;
  466. //看直播间是否需要刷新UI
  467. SendNotification(@"kNotification_IM_RedNumChange")
  468. });
  469. }
  470. #pragma mark - Tencent IM Filter
  471. // 收到所有会话的未读总数变更通知
  472. - (void)onTotalUnreadMessageCountChanged:(UInt64)totalUnreadCount {
  473. // totalUnreadCount 为未读消息总数
  474. [self updateTheUnreadCountWith:totalUnreadCount];
  475. }
  476. - (void)onUserSigExpired{
  477. //token过期 - 获取token重新登录
  478. [self needGetNewTimChatToken];
  479. }
  480. - (void)onRecvNewMessage:(V2TIMMessage *)msg{
  481. // 收到新消息 - 站内通知
  482. [[MOChatNotificationManager sharedManager] showNotification:msg];
  483. }
  484. #pragma mark - About Tabbar
  485. - (void)setupTabbar {
  486. MOCustomTabBar *customTabBar = [[MOCustomTabBar alloc] init];
  487. [self setValue:customTabBar forKey:@"tabBar"]; // 替换系统的 tabBar
  488. self.customTabBarView = [[MOCustomTabBarView alloc] initWithFrame:self.tabBar.bounds];
  489. self.customTabBarView.delegate = self;
  490. CGRect mainFrame = self.customTabBarView.frame;
  491. self.customTabBarView.frame = mainFrame;
  492. [customTabBar addSubview:self.customTabBarView];
  493. customTabBar.customTabBarView = self.customTabBarView;
  494. customTabBar.backgroundImage = [UIImage new];
  495. customTabBar.shadowImage = [UIImage new];
  496. customTabBar.backgroundColor = [UIColor clearColor];
  497. }
  498. - (void)addTabbarChildViewControllers{
  499. UINavigationController *squareNav = [self setUpChildController:self.squareVC];
  500. [self addChildViewController:squareNav];
  501. UINavigationController *exploreNav = [self setUpChildController:self.exploreVC];
  502. [self addChildViewController:exploreNav];
  503. UINavigationController *infomationNav = [self setUpChildController:self.infomationVC];
  504. [self addChildViewController:infomationNav];
  505. UINavigationController *mineNav = [self setUpChildController:self.mineVC];
  506. [self addChildViewController:mineNav];
  507. }
  508. - (void)toResetSetupTabbar{
  509. [self toResetTabbar];
  510. //登录IM
  511. [self toLoginIM];
  512. if(!self.isNormalOpen){//是否是已登录的第一次打开
  513. //检查可能需要的弹窗
  514. [self mayBeShowAlertAction];
  515. }
  516. else{
  517. //已登录的第一次打开
  518. //调用个人信息接口, 一些装饰类的数据可能需要刷新 (个人信息)
  519. [self getHttpDataAboutUserInfo];
  520. }
  521. //获取启动页数据
  522. [self toGetLaunchImageAdData];
  523. [self setupBugly];
  524. }
  525. /// 重置tabbar
  526. - (void)toResetTabbar {
  527. self.selectedIndex = 0;
  528. [self.customTabBarView setSelectedIndex:0];
  529. NSMutableArray *newViewControllers = [NSMutableArray array];
  530. self.squareVC = nil;
  531. UINavigationController *squareNav = [self setUpChildController:self.squareVC];
  532. [newViewControllers addObject:squareNav];
  533. self.exploreVC = nil;
  534. UINavigationController *exploreNav = [self setUpChildController:self.exploreVC];
  535. [newViewControllers addObject:exploreNav];
  536. self.infomationVC = nil;
  537. UINavigationController *infomationNav = [self setUpChildController:self.infomationVC];
  538. [newViewControllers addObject:infomationNav];
  539. self.mineVC = nil;
  540. UINavigationController *mineNav = [self setUpChildController:self.mineVC];
  541. [newViewControllers addObject:mineNav];
  542. self.viewControllers = newViewControllers;
  543. }
  544. //有可能有弹窗的方法
  545. - (void)mayBeShowAlertAction{
  546. WEAKSELF
  547. [kHttpManager getGuideWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  548. if (kCode_Success) {
  549. int regGuide = [data[@"data"][@"regGuide"] intValue];
  550. if (regGuide == 1) {
  551. MOFirstInfoSetVC *vc = [[MOFirstInfoSetVC alloc] init];
  552. [weakSelf loginPageActionWithVC:vc];
  553. } else {
  554. [NSObject cancelPreviousPerformRequestsWithTarget:weakSelf selector:@selector(toJudgeShowAlertView) object:nil];
  555. [weakSelf performSelector:@selector(toJudgeShowAlertView) withObject:nil afterDelay:0.5];
  556. }
  557. }
  558. }];
  559. }
  560. - (void)loginPageActionWithVC:(UIViewController *)vc {
  561. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  562. nav.modalPresentationStyle = UIModalPresentationFullScreen;
  563. [nav.navigationBar setHidden:YES];
  564. [self presentModalViewController:nav animated:YES];
  565. }
  566. - (void)toJudgeShowAlertView{
  567. if(self.isAgainLogin){
  568. self.isAgainLogin = NO;
  569. return;
  570. }
  571. //主播判断是否有直播间
  572. [self toGetMyLivingRoom];
  573. //检查版本
  574. [self toCheckAppVersion];
  575. //当前签到弹窗
  576. [self toGetTheSignInHttpData];
  577. //勋章弹窗
  578. [self toGetTheEventHttpData];
  579. //检查是否引流跳转
  580. [self toCheckAgentJumpRoom];
  581. }
  582. - (void)getHttpDataAboutUserInfo{
  583. WEAKSELF
  584. [kHttpManager getMeUserInfoWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  585. if(kCode_Success){
  586. //更新个人信息偏好缓存
  587. [MODataManager saveUserInfo:data];
  588. }
  589. }];
  590. }
  591. - (void)toShowDiamondWinAlertView{
  592. WEAKSELF
  593. MODiamondWinAlertView *view = [MODiamondWinAlertView moDiamondWinAlertView];
  594. [view showDiamondWinAlertView];
  595. view.openDiamondWinBlock = ^{
  596. MODiaWinVC *vc = [[MODiaWinVC alloc] init];
  597. vc.hidesBottomBarWhenPushed = YES;
  598. [weakSelf.selectedViewController pushViewController:vc animated:YES];
  599. };
  600. }
  601. - (void)ChangeNeedShowAlert{
  602. //签到弹窗, 切换账号后, 也需要弹出
  603. [self toShowAlertWithChangeAccount];
  604. //检查版本
  605. [self toCheckAppVersion];
  606. }
  607. - (void)toShowAlertWithChangeAccount{
  608. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(toGetTheSignInHttpData) object:nil];
  609. [self performSelector:@selector(toGetTheSignInHttpData) withObject:nil afterDelay:0.5];
  610. }
  611. static BOOL signInTag = NO;
  612. - (void)toGetTheSignInHttpData{
  613. if(signInTag){
  614. return;
  615. }
  616. signInTag = YES;
  617. [self performSelector:@selector(updateTheSignInTag) withObject:nil afterDelay:2.0];
  618. //弹窗管理器接口 (首充/签到弹窗)
  619. [self toShowTheDiamondWinnerView];
  620. }
  621. - (void)updateTheSignInTag{
  622. signInTag = NO;
  623. }
  624. - (void)toShowTheDiamondWinnerView{
  625. WEAKSELF
  626. [kHttpManager getTheDialogInfoWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  627. if(kCode_Success){
  628. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  629. MOAlertBaseData *baseData = [MOAlertBaseData modelObjectWithDictionary:data[@"data"]];
  630. if(baseData.actBigWinner){
  631. [weakSelf toShowDiamondWinAlertView];
  632. }
  633. [MOSvgaSourceManage shareManager].floatings = [baseData.floatings copy];
  634. SendObjNotification(@"MOFirstRecharge_UpdataView", baseData.floatings);
  635. self.floatingsArr = baseData.floatings;
  636. [weakSelf toShowAlertManageViewWith:baseData.dialogsData];
  637. }
  638. else{
  639. MOLogV(@"getTheDialogInfoWithParams 接口报错了");
  640. #if kAPP_Environment == 1
  641. #elif kAPP_Environment == 2
  642. kShowNetError(data)
  643. #endif
  644. }
  645. }];
  646. }
  647. - (void)toShowAlertManageViewWith:(NSArray *)codesArr{
  648. if(codesArr.count == 0){
  649. return;
  650. }
  651. NSMutableArray *dataArr = [NSMutableArray array];
  652. for (MODialogsData *object in codesArr) {
  653. if(object.type > 0 && object.type < 4){
  654. [dataArr addObject:object];
  655. } else if (object.type == 4) {//显示新手礼包弹窗
  656. [[MODataCache sharedYYCache] setObject:object forKey:kNewUserGiftPack];
  657. SendObjNotification(@"kNotification_ShowNewComerGiftView", object)
  658. return;
  659. }
  660. }
  661. NSArray *sortedArray = [dataArr sortedArrayUsingComparator:^NSComparisonResult(MODialogsData * obj1, MODialogsData * obj2) {
  662. if (obj1.type == 3 && obj2.type != 3) {
  663. return NSOrderedAscending; // obj1排在前面
  664. }
  665. if (obj2.type == 3 && obj1.type != 3) {
  666. return NSOrderedDescending; // obj2排在前面
  667. }
  668. if (obj1.type == 1 && obj2.type != 1) {
  669. return NSOrderedAscending; // obj1排在前面
  670. }
  671. if (obj2.type == 1 && obj1.type != 1) {
  672. return NSOrderedDescending; // obj2排在前面
  673. }
  674. return NSOrderedSame; // 如果 type 相等,保持原顺序
  675. }];
  676. SendObjNotification(@"Noti_MOActivityManageView", sortedArray)
  677. }
  678. - (void)toShowSignInAlertViewWith:(MOSignBaseData *)data{
  679. WEAKSELF
  680. MOSignInAlertView *view = [MOSignInAlertView moSignInAlertView];
  681. view.isGet = NO;
  682. view.baseData = data;
  683. view.toTaskWebBlock = ^{
  684. MOWebViewController *vc = [[MOWebViewController alloc] init];
  685. NSString *urlStr = [NSString stringWithFormat:@"%@/#/taskCenter?tagName=dailyTasks",kNetPath_Web_Base];
  686. vc.webUrl = [NSURL URLWithString:urlStr];
  687. vc.hidesBottomBarWhenPushed = YES;
  688. [weakSelf.selectedViewController pushViewController:vc animated:YES];
  689. };
  690. [view showSignInAlertView];
  691. }
  692. - (UINavigationController *)setUpChildController:(UIViewController *)childVC{
  693. UINavigationController *childVcNvc = [[UINavigationController alloc]initWithRootViewController:childVC];
  694. childVcNvc.navigationBar.tintColor = [UIColor whiteColor];
  695. childVcNvc.navigationBar.translucent = NO;
  696. NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
  697. textAttrs[NSForegroundColorAttributeName] = [MOTools colorWithHexString:@"#333333" alpha:1.0];
  698. textAttrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:17];
  699. [childVcNvc.navigationBar setTitleTextAttributes:textAttrs];
  700. return childVcNvc;
  701. }
  702. - (void)toCheckAgentJumpRoom {
  703. if (!GetToken) return;
  704. NSString *roomId = (NSString *)[[MODataCache sharedYYCache] objectForKey:kAgentJumpRoomId];
  705. if (roomId.length == 0) {
  706. return;
  707. }
  708. if ([self isInLiveRoom]) {
  709. return;
  710. }
  711. // 移除记录
  712. [[MODataCache sharedYYCache] removeObjectForKey:kAgentJumpRoomId];
  713. [MOShowAgoraKitManager shareManager].isFirstShow = YES;
  714. MOLiveList *model = [[MOLiveList alloc] init];
  715. model.id = roomId;
  716. MOShowLivePagesVC *vc = [[MOShowLivePagesVC alloc] init];
  717. vc.userType = MOShowLiveAudienceType;
  718. vc.roomList = @[model].mutableCopy;
  719. vc.focusIndex = 0;
  720. vc.hidesBottomBarWhenPushed = YES;
  721. [self.selectedViewController pushViewController:vc animated:YES];
  722. }
  723. #pragma mark - CustomTabBarViewDelegate
  724. - (void)customTabBarDidSelectIndex:(NSInteger)index {
  725. [self.customTabBarView setSelectedIndex:index];
  726. if(index == self.selectedIndex){
  727. if(index == 0){
  728. SendNotification(@"MOSquareListVC_Refresh");
  729. }
  730. else if (index == 1){
  731. SendNotification(@"MOExploreVC_Refresh");
  732. }
  733. }
  734. //正常点击
  735. self.selectedIndex = index;
  736. if(index!= 3){
  737. [[MORefreshViewManage shareManager] setNeedRefreshWithCode:@"MOMineVC"];
  738. }
  739. }
  740. - (void)showTabbarWithAnimation:(BOOL)animation {
  741. CGFloat duration = animation ? 0.5 : 0;
  742. // 如果已有动画,则取消当前动画
  743. [self.propertyAnimator stopAnimation:YES];
  744. // 创建一个新的动画
  745. self.propertyAnimator = [[UIViewPropertyAnimator alloc] initWithDuration:duration curve:UIViewAnimationCurveEaseInOut animations:^{
  746. self.customTabBarView.alpha = 1.0;
  747. self.customTabBarView.transform = CGAffineTransformIdentity;
  748. }];
  749. // 开始动画
  750. [self.propertyAnimator startAnimation];
  751. }
  752. - (void)hideTabbarWithAnimation:(BOOL)animation {
  753. CGFloat duration = animation ? 0.5 : 0;
  754. // 如果已有动画,则取消当前动画
  755. [self.propertyAnimator stopAnimation:YES];
  756. // 创建一个新的动画
  757. self.propertyAnimator = [[UIViewPropertyAnimator alloc] initWithDuration:duration curve:UIViewAnimationCurveEaseInOut animations:^{
  758. self.customTabBarView.alpha = 0.0;
  759. self.customTabBarView.transform = CGAffineTransformMakeTranslation(0, 30);
  760. }];
  761. // 开始动画
  762. [self.propertyAnimator startAnimation];
  763. }
  764. - (void)toOpenTheLiveRoom{
  765. [self.squareVC toOpenTheLiveRoom];
  766. }
  767. #pragma mark - Lazy
  768. - (MOSquareListVC *)squareVC{
  769. if(_squareVC == nil){
  770. _squareVC = [[MOSquareListVC alloc] init];
  771. _squareVC.homePageShowBlock = ^{
  772. [[MOSvgaSourceManage shareManager] toGetTheBaseResources];
  773. };
  774. }
  775. return _squareVC;
  776. }
  777. - (MOExploreVC *)exploreVC{
  778. if(_exploreVC == nil){
  779. _exploreVC = [[MOExploreVC alloc] init];
  780. }
  781. return _exploreVC;
  782. }
  783. - (MOInfomationVC *)infomationVC{
  784. if(_infomationVC == nil){
  785. _infomationVC = [[MOInfomationVC alloc] init];
  786. }
  787. return _infomationVC;
  788. }
  789. - (MOMineVC *)mineVC{
  790. if(_mineVC == nil){
  791. _mineVC = [[MOMineVC alloc] init];
  792. }
  793. return _mineVC;
  794. }
  795. - (void)dealloc
  796. {
  797. [[NSNotificationCenter defaultCenter] removeObserver:self];
  798. [[V2TIMManager sharedInstance] removeConversationListener:self];
  799. }
  800. - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
  801. return UIInterfaceOrientationMaskPortrait;
  802. }
  803. - (void)toCheckAppVersion{
  804. if (self.versionView.superview) {//防止重复弹出
  805. return;
  806. }
  807. [kHttpManager toCheckAppVersionWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  808. if(kCode_Success){
  809. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  810. NSDictionary *baseDict = [MODataManager objectOrNilForKey:@"data" fromDictionary:data];
  811. if(baseDict){
  812. MOVersionModel *model = [MOVersionModel modelWithJSON:baseDict];
  813. MONewVersionView *view = [MONewVersionView moNewVersionView];
  814. view.model = model;
  815. [view showNewVersionView];
  816. self.versionView = view;
  817. }
  818. }
  819. else{
  820. #if kAPP_Environment == 1
  821. #elif kAPP_Environment == 2
  822. kShowNetError(data)
  823. #endif
  824. }
  825. }];
  826. }
  827. - (void)toGetLaunchImageAdData{
  828. //1=首页图片,2=直播间图片,3=New页图片,4=启动页图片,5=开播页图片,6=语音列表图片
  829. NSDictionary *dict = @{@"category":@(4)};
  830. [kHttpManager getBaseBannerListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  831. if(kCode_Success){
  832. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  833. MOBannerData *baseModel = [MOBannerData modelObjectWithDictionary:data[@"data"]];
  834. [[MODataCache sharedYYCache] setObject:baseModel forKey:kFirstLaunchInfo];
  835. }
  836. else{
  837. #if kAPP_Environment == 1
  838. #elif kAPP_Environment == 2
  839. kShowNetError(data)
  840. #endif
  841. }
  842. }];
  843. }
  844. #pragma mark - 升级/勋章
  845. - (void)toGetTheEventHttpData{
  846. return;
  847. NSDictionary *basePage = @{@"size":@(100),@"next":@""};
  848. NSDictionary *baseDict = @{@"page":basePage};
  849. [kHttpManager toGetUserEventListWithParams:baseDict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  850. if(kCode_Success){
  851. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  852. MOEventData *baseData = [MOEventData modelObjectWithDictionary:data[@"data"]];
  853. MOEventList *showModel;
  854. if(baseData.eventList.count > 0){
  855. showModel = baseData.eventList.lastObject;
  856. MOGetShowView *view = [MOGetShowView moGetShowView];
  857. view.viewModel = showModel;
  858. [view showGetShowView];
  859. }
  860. }
  861. else{
  862. MOLogV(@"toGetTheEventHttpData 接口报错了");
  863. }
  864. }];
  865. }
  866. - (void)setupBugly{
  867. #if !TARGET_IPHONE_SIMULATOR
  868. BuglyConfig * config = [[BuglyConfig alloc] init];
  869. //日志级别
  870. config.blockMonitorEnable = YES;
  871. config.blockMonitorTimeout = 3.5;
  872. #if kAPP_Environment == 1
  873. config.reportLogLevel = BuglyLogLevelError;
  874. [Bugly startWithAppId:KBuglyKeyId config:config];
  875. #elif kAPP_Environment == 2
  876. config.reportLogLevel = BuglyLogLevelVerbose;
  877. [Bugly startWithAppId:KBuglyKeyId developmentDevice:YES config:config];
  878. #endif
  879. NSString *userNo = GetUserNo;
  880. NSString *userName = GetNickName;
  881. if(userName.length == 0){
  882. userName = [UIDevice currentDevice].name;
  883. }
  884. if(userNo.length == 0){
  885. userNo = userName;
  886. }
  887. [Bugly setUserIdentifier:userNo];
  888. #endif
  889. }
  890. @end