| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111 |
- //
- // MOMainTabController.m
- // MiMoLive
- //
- // Created by SuperC on 2023/10/10.
- //
- #import "MOMainTabController.h"
- #import "MOExploreVC.h"
- #import "MOSquareListVC.h"
- #import "MOInfomationVC.h"
- #import "MOMineVC.h"
- #import "MOCreateLiveVC.h"
- #import "MOUploadDeviceTool.h"
- #import "MOMineSetUpVC.h"
- #import "MOShowLivePagesVC.h"
- #import "MOTopUpVC.h"
- #import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
- #import "MONewVersionView.h"
- #import "MOTopUpView.h"//充值弹窗
- #import "MOBingMobileVC.h"//绑定手机界面
- #import "MOWebViewController.h"
- #import "MOClickConfigManager.h"
- #import "MOActivityCenterVC.h"
- #import "UIImage+Color.h"
- #if !TARGET_IPHONE_SIMULATOR
- #import <Bugly/Bugly.h>
- #endif
- #import "MOSignInAlertView.h"
- #import "MODiamondWinAlertView.h"
- #import "MODiaWinVC.h"
- #import "MOChatViewController.h"
- #import "MOThemeManager.h"
- //美颜资源下载
- #import "TEDownloader.h"
- #import "MOBeautyResDataModels.h"
- #import "TEUIConfig.h"
- //腾讯IM
- #import "TUICore/TUILogin.h"
- #import "TIMPush/TIMPush.h"
- #import "MOFirstInfoSetVC.h"
- #import "MONetAPIClient.h"
- #import "MOMainTabController+ChatNotifi.h"
- #import "MOCustomTabBarView.h"
- #import "MOBeautyDownloadManager.h"
- #import "MOVersionModel.h"
- #import "MOCustomTabBar.h"
- #import <AVFoundation/AVFoundation.h>
- static MOMainTabController *_sharedSingleton = nil;
- static dispatch_once_t onceToken;
- @interface MOMainTabController ()<V2TIMConversationListener,V2TIMSDKListener,V2TIMAdvancedMsgListener, MOCustomTabBarViewDelegate>
- @property (nonatomic, strong) MOCustomTabBarView *customTabBarView;
- /** */
- @property (nonatomic, strong) MOSquareListVC *squareVC;
- /** */
- @property (nonatomic, strong) MOExploreVC *exploreVC;
- /** */
- @property (nonatomic, strong) MOInfomationVC *infomationVC;
- /** */
- @property (nonatomic, strong) MOMineVC *mineVC;
- /** 用来表明退出登录短时间只弹出一次 */
- @property (nonatomic, assign) BOOL isJustFirstLoginAction;
- /** 是否到重新登录界面 */
- @property (nonatomic, assign) BOOL isAgainLogin;
- /** 无钻石提示view */
- @property (nonatomic, strong) MOTitleNormalAlertView *theTipView;
- @property (nonatomic, strong) UIViewPropertyAnimator *propertyAnimator;
- @property (nonatomic, strong) MONewVersionView *versionView;
- @end
- @implementation MOMainTabController
- + (instancetype)sharedSingleton
- {
- static dispatch_once_t onceTokenK;
- dispatch_once(&onceTokenK, ^
- {
- // 要使用self来调用
-
- _sharedSingleton = [[self alloc] init];
- });
- return _sharedSingleton;
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- // 删除系统自动生成的UITabBarButton
- for (UIView *child in self.tabBar.subviews) {
- if ([child isKindOfClass:[UIControl class]]) {
- [child removeFromSuperview];
- }
- }
- }
- - (void)viewWillLayoutSubviews {
- [super viewWillLayoutSubviews];
- // 删除系统自动生成的UITabBarButton
- for (UIView *child in self.tabBar.subviews) {
- if ([child isKindOfClass:[UIControl class]]) {
- [child removeFromSuperview];
- }
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self setupTabbar];
- [self addTabbarChildViewControllers];
- //AgoraRtcEngineKit 初始化
- [[MOShowAgoraKitManager shareManager] prepareEngine];
-
- //美颜License检查, 成功后初始化相应的RTC
- // [[MOBeautyDownloadManager shareManager] theXmagicCheckLicense];
- [[MOBeautyDownloadManager shareManager] initCacheData];
- [[MOBeautyDownloadManager shareManager] setupBeResource];//设置火山美颜资源路径
- [[MOBeautyDownloadManager shareManager] toGetTheBytesResCacheArKeyData];//获取火山美颜资源ArKey缓存数据
-
- //进入svga资源获取
- [[MOSvgaSourceManage shareManager] loadDictCache];
- [[MOSvgaSourceManage shareManager] toGetGiftCategoryListDataAndNeedShowError:NO];
- [[MOSvgaSourceManage shareManager] toGetTheWameDataAndNeedShowError:NO];
-
- //刷新管理
- [[MORefreshViewManage shareManager] resetAllProperty];
-
- [[MOUploadDeviceTool shareTool] uploadDeviceInfo];
-
- [self addNotification];
-
- self.isJustFirstLoginAction = NO;
- self.isAgainLogin = NO;
-
- //webp解码器
- SDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];
- [[SDImageCodersManager sharedManager] addCoder:webPCoder];
-
- //主题管理器
- // [[MOThemeManager shareManager] loadThemeData];
-
- [self setChatNotifiClickBlock];//设置APP内消息点击回调
- }
- - (void)addNotification{
- ReceiveNotification(@selector(againLoginAction:), @"kNotification_AgainLogin")//其他设备登录
- ReceiveNotification(@selector(noMoneyTipShow), @"kNotification_NoMoney")//钻石不足
- ReceiveNotification(@selector(mayBeShowAlertAction), @"kNotification_FirstShowNoti")//如果有开屏广告页, 则稍后检查相应弹窗
- ReceiveNotification(@selector(noBindPhoenTipShow), @"kNotification_NoBindPhone")//没有绑定手机 - 点赞活动
- ReceiveNotification(@selector(toCheckTheIMStatus), @"kNotification_CheckTheIMStatus")//检测IM连接状态
- ReceiveNotification(@selector(toOpenTheLiveRoom), @"kNotification_OpenTheLiveRoom")//开播
- ReceiveNotification(@selector(toCheckAgentJumpRoom), @"kNotification_adjustAgent")
- }
- - (void)noBindPhoenTipShow{
-
- NSDate *lastTime = [MOTools getTimeOfShowBind];
- BOOL needShow = YES;
- if(lastTime){
- needShow = [MOTools shouldShowAlertWithLastTime:lastTime];
- }
-
- if(needShow == NO){
- return;
- }
-
- //设置显示的时间
- [MOTools setTimeOfShowBindDevice:[NSDate date]];
-
- MOTitleNormalAlertView *alertView = [[MOTitleNormalAlertView alloc] init];
- alertView.isSingleBtn = YES;
- alertView.isStrongBg = YES;
- alertView.isShowCloseBtn = YES;
- alertView.bgImgView.hidden = YES;
- alertView.titleLabel.text = NSLocalString(@"mimo_alert_normal_tip");
- alertView.subTitleLabel.text = NSLocalString(@"mimo_alert_no_bind_tip");
- [alertView.confirmBtn setTitle:NSLocalString(@"mimo_alert_no_bind_sure_tip") forState:UIControlStateNormal];
- alertView.confirmBlock = ^{
- MOMainTabController *mainTabbar = [MOMainTabController sharedSingleton];
- UINavigationController *nav = mainTabbar.selectedViewController;
- if (nav.presentedViewController) {
- if ([nav isKindOfClass:[UINavigationController class]]) {
- UINavigationController *presentingNavigationController = (UINavigationController *)nav.presentedViewController;
- MOBingMobileVC *vc = [[MOBingMobileVC alloc] init];
- [presentingNavigationController pushViewController:vc animated:YES];
- }
- } else {
- MOBingMobileVC *vc = [[MOBingMobileVC alloc] init];
- [nav pushViewController:vc animated:YES];
- }
- };
- [alertView show];
- }
- - (void)noMoneyTipShow{
-
- if(self.theTipView){
- return;
- }
-
- WEAKSELF
- self.theTipView = [[MOTitleNormalAlertView alloc] init];
- self.theTipView.subTitleLabel.text = NSLocalString(@"mimo_no_money_tip");
- [self.theTipView.cancelBtn setTitle:NSLocalString(@"mimo_Cancel") forState:UIControlStateNormal];
- [self.theTipView.confirmBtn setTitle:NSLocalString(@"mimo_no_money_jump") forState:UIControlStateNormal];
- self.theTipView.isStrongBg = YES;
- self.theTipView.confirmBlock = ^{
- MOTopUpView *view = [MOTopUpView moTopUpView];
- [view showTopUpView];
- };
- self.theTipView.dismissBlock = ^{
- weakSelf.theTipView = nil;
- };
- [self.theTipView show];
- }
- - (void)toGetMyLivingRoom{
-
- BOOL isAnchor = GetIsAnchor;
- if(isAnchor){
- WEAKSELF
- [kHttpManager theAnchorGetLiveRoomWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MOLiveDetail *dataModel = [MOLiveDetail modelObjectWithDictionary:data[@"data"]];
- [weakSelf toCloseTheRoomOrContinueWith:dataModel];
- }
- else{
- MOLogV(@"getGiftHttpDataWith 接口报错了");
- }
- }];
- }
- }
- - (void)toCloseTheRoomOrContinueWith:(MOLiveDetail *)model{
-
- WEAKSELF
- if(model.currentRoom.id.length > 0){
- //中心弹窗
- MOTitleNormalAlertView *alertView = [[MOTitleNormalAlertView alloc] init];
- alertView.subTitleLabel.text = NSLocalString(@"mimo_room_living_open_tip");
- [alertView.cancelBtn setTitle:NSLocalString(@"mimo_room_living_close_living") forState:UIControlStateNormal];
- [alertView.confirmBtn setTitle:NSLocalString(@"mimo_room_living_continue_living") forState:UIControlStateNormal];
- alertView.isStrongBg = YES;
- alertView.cancelBlock = ^{
- [weakSelf toCloseTheLiveRoomWithRoomId:model.currentRoom.id];
- };
- alertView.confirmBlock = ^{
- [weakSelf toShowRoomWith:model];
- };
- [alertView show];
- }
- }
- //关闭直播间
- - (void)toCloseTheLiveRoomWithRoomId:(NSString *)roomId{
- WEAKSELF
- NSDictionary *dict = @{@"id":roomId};
- [kHttpManager toCloseTheLiveRoomWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- MOLogV(@"关闭直播间接口调用");
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_room_end_tip_anchor")];
- SendNotification(@"MOSquareListVC_Refresh");
- }];
- }
- - (void)toShowRoomWith:(MOLiveDetail *)model{
-
- BOOL isHaveBeautyRes = [TEDownloader toCheckTheBeautyRes];
- if(!isHaveBeautyRes){
- [[MOBeautyDownloadManager shareManager] checkAndDownloadBeautyData];
- WEAKSELF
- [MOBeautyDownloadManager shareManager].progressBlock = ^(CGFloat progress) {
- [weakSelf.squareVC updateDownloadBeautyData:progress];
- };
- [MOBeautyDownloadManager shareManager].completeBlock = ^{
- [weakSelf.squareVC downloadBeautyDataSuccess];
- };
- return;
- }
-
- //MARK 检查用户是否对摄像头麦克风授权,未授权不能调用录制功能
- AVAuthorizationStatus videoStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
- AVAuthorizationStatus audioStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
-
- //没有打开摄像头权限
- if(videoStatus != AVAuthorizationStatusAuthorized){
- [MOCreateLiveVC requestCameraPermissionWithCompletion:^(BOOL open) {
- if(!open){
- 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];
- [alert show];
- }
- }];
- return;
- }
-
- //没有打开麦克风权限
- if(audioStatus != AVAuthorizationStatusAuthorized){
- [MOCreateLiveVC requestAudioPermissionWithCompletion:^(BOOL open) {
- if(!open){
- 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];
- [alert show];
- }
- }];
- return;
- }
-
- [MOShowAgoraKitManager shareManager].isCreatLive = YES;
-
- MOClickConfigManager *configManager = [MOClickConfigManager shareManager];
- configManager.durationTask = model.durationTask;
-
- MOShowLivePagesVC *vc = [[MOShowLivePagesVC alloc] init];
- vc.isCreatLive = YES;
- vc.userType = MOShowLiveAnchorType;
- vc.roomList = @[model.currentRoom].mutableCopy;
- vc.liveModel = model;
- vc.isNeedSetBeauty = YES;
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
- nav.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:nav animated:YES completion:nil];
- }
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
- if (buttonIndex == 1) { // 去设置界面,开启相机访问权限
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
- }
- }
- - (void)againLoginAction:(NSNotification *)notification{
-
- WEAKSELF
- kMainThreadBlock(^{
- if (!weakSelf.isJustFirstLoginAction){
- [MOMineSetUpVC toLoginVCAndShowTip:YES];
-
- weakSelf.isJustFirstLoginAction = YES;
- weakSelf.isAgainLogin = YES;
- [weakSelf performSelector:@selector(changJustFirstLoginAction) withObject:nil afterDelay:2.0];
- }
- })
- }
- - (void)changJustFirstLoginAction{
- self.isJustFirstLoginAction = NO;
- }
- - (BOOL)isInLiveRoom {
- UINavigationController *nav = self.selectedViewController;
-
- if (nav.presentedViewController) {
- if ([nav isKindOfClass:[UINavigationController class]]) {
- UINavigationController *presentingNavigationController = (UINavigationController *)nav.presentedViewController;
-
- BOOL isHaveLive = NO;
-
- for (UIViewController *vc in presentingNavigationController.viewControllers) {
- if([vc isKindOfClass:[MOShowLivePagesVC class]]){
- isHaveLive = YES;
- break;
- }
- }
-
- if(isHaveLive){
- [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_joined_live_room_tip")];
- return YES;
- }
- }
- }
-
- if ([nav isKindOfClass:[UINavigationController class]]) {
- BOOL isHaveLive = NO;
-
- for (UIViewController *vc in nav.viewControllers) {
- if([vc isKindOfClass:[MOShowLivePagesVC class]]){
- isHaveLive = YES;
- break;
- }
- }
-
- if(isHaveLive){
- [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_joined_live_room_tip")];
- return YES;
- }
- }
- return NO;
- }
- #pragma mark - IM Login
- - (void)toLoginIM{
-
- NSString *userNameStirng = GetUserId;
- NSString *imToken = GetImToken;
- NSString *t_imToken = GetTentImToken;
- [self toLoginTheTencentIM];//腾讯IM
-
- [MOTencentSendManage shareManager].myUserId = userNameStirng;
- [MOTencentSendManage createCachePath];
- }
- - (void)toLoginTheTencentIM{
- NSString *userNameStirng = GetUserId;
- NSString *t_imToken = GetTentImToken;
-
- BOOL isOnlyUseTim = GetOnlyUserTimBool;
-
- BOOL isGetTheTimStatus = [MOTencentSendManage shareManager].isGetTheTimStatus;
- //在isOnlyUseTim为NO时, 需要调用一次获取是否启动腾讯IM
- if(!isGetTheTimStatus && !isOnlyUseTim){
- [MOTencentSendManage shareManager].isGetTheTimStatus = YES;
- [self needGetNewTimChatToken];
- return;
- }
-
- if(t_imToken.length == 0){
- //旧版本升级到新版本 - 并不会调用获取TimToken
- [self needGetNewTimChatToken];
- return;
- }
-
- if(userNameStirng.length == 0){
- return;
- }
-
- if(isOnlyUseTim){
- // 添加会话监听器
- [[V2TIMManager sharedInstance] removeConversationListener:self];
- [[V2TIMManager sharedInstance] addConversationListener:self];
-
- // 添加高级消息监听器
- [[V2TIMManager sharedInstance] removeAdvancedMsgListener:self];
- [[V2TIMManager sharedInstance] addAdvancedMsgListener:self];
- }
-
- [[V2TIMManager sharedInstance] addIMSDKListener:self];
-
- [self toSetTheTencentNormalConfig];//如果使用腾讯IM - 一些通用样式设置
-
- WEAKSELF
- [TUILogin login:KTentIMAppID userID:userNameStirng userSig:t_imToken succ:^{
- // 获取红点数
- MOLogV(@"TUILogin - 成功");
- [weakSelf toRegisterTencentPush];
- [weakSelf getAllTencentIMUnreadNum];
- } fail:^(int code, NSString * _Nullable msg) {
- MOLogV(@"TUILogin - 失败");
- }];
- }
- - (void)toRegisterTencentPush{
- const int sdkAppId = KTentIMAppID;
- NSString *appKey = KTentSDKAppKey;
-
- [TIMPushManager registerPush:sdkAppId appKey:nil succ:^(NSData * _Nonnull deviceToken) {
- MOLogV(@"TIMPushManager registerPush success");
- } fail:^(int code, NSString * _Nonnull desc) {
- MOLogV(@"TIMPushManager registerPush fail code %d desc %@",code,desc);
- }];
- }
- - (void)toSetTheTencentNormalConfig{
- [TUIConfig defaultConfig].avatarType = TAvatarTypeRounded;
- [TUIConfig defaultConfig].defaultAvatarImage = [UIImage imageNamed:@"icon_mine_placeHolder"];
- }
- - (void)toCheckTheIMStatus{
- WEAKSELF
-
- NSString *token = [NSString stringWithFormat:@"%@",GetToken];
- if(token.length == 0){
- return;
- }
-
- [self toCheckTheTencentIMStatus];//检测腾讯连接
- }
- - (void)toCheckTheTencentIMStatus{
- //腾讯IM没有登录上
- if(!TUILogin.isUserLogined){
- [self needGetNewTimChatToken];
- }
- }
- - (void)needGetNewTimChatToken{
- WEAKSELF
-
- //先执行登出操作
- [TUILogin logout:^{
-
- } fail:^(int code, NSString * _Nullable msg) {
-
- }];
- //重新获取腾讯登录Token
- [kHttpManager toGetChatTokenWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
-
- NSString *tempStr = [MODataManager objectOrNilForKey:@"tim" fromDictionary:data[@"data"]];
-
- //是否只使用 Tim (腾讯IM)
- BOOL isUseTim = [[MODataManager objectOrNilForKey:@"onlyUseTim" fromDictionary:data[@"data"]] boolValue];
- [[NSUserDefaults standardUserDefaults] setBool:isUseTim forKey:kOnlyUseTimIM];
-
- if(tempStr.length > 0){
- [[NSUserDefaults standardUserDefaults] setObject:tempStr forKey:kTent_ImToken];
- [[NSUserDefaults standardUserDefaults] synchronize];
-
- [weakSelf toLoginTheTencentIM];
- }
- }
- else{
- MOLogV(@"toGetImTokenWithParams 接口报错了");
- }
- }];
- }
- - (void)getAllTencentIMUnreadNum{
-
- BOOL isOnlyUseTim = GetOnlyUserTimBool;
-
- if(isOnlyUseTim){
- WEAKSELF
- [V2TIMManager.sharedInstance getTotalUnreadMessageCount:^(UInt64 totalUnreadCount) {
- [weakSelf updateTheUnreadCountWith:totalUnreadCount];
- } fail:^(int code, NSString *desc) {
-
- }];
- }
- }
- #pragma mark - EaseIMKitManagerDelegate
- - (void)conversationsUnreadCountUpdate:(NSInteger)unreadCount{
- [self updateTheUnreadCountWith:unreadCount];
- }
- - (void)updateTheUnreadCountWith:(NSInteger)unreadCount{
- NSString *badgeStr = @"";
- if (unreadCount > 0)
- {
- if (unreadCount < 100)
- {
- badgeStr = [NSString stringWithFormat:@"%ld",(long)unreadCount];
- }
- else
- {
- badgeStr = @"99+";
- }
- }
- dispatch_async(dispatch_get_main_queue(), ^
- {
- [self.customTabBarView setIMUnreadMsgCount:badgeStr];
-
- //更新单例里面相应的未读数标记
- [MOSvgaSourceManage shareManager].theUserRedNum = unreadCount;
-
- //看直播间是否需要刷新UI
- SendNotification(@"kNotification_IM_RedNumChange")
- });
- }
- #pragma mark - Tencent IM Filter
- // 收到所有会话的未读总数变更通知
- - (void)onTotalUnreadMessageCountChanged:(UInt64)totalUnreadCount {
- // totalUnreadCount 为未读消息总数
- [self updateTheUnreadCountWith:totalUnreadCount];
- }
- - (void)onUserSigExpired{
- //token过期 - 获取token重新登录
- [self needGetNewTimChatToken];
- }
- - (void)onRecvNewMessage:(V2TIMMessage *)msg{
- // 收到新消息 - 站内通知
- [[MOChatNotificationManager sharedManager] showNotification:msg];
- }
- #pragma mark - About Tabbar
- - (void)setupTabbar {
-
- MOCustomTabBar *customTabBar = [[MOCustomTabBar alloc] init];
- [self setValue:customTabBar forKey:@"tabBar"]; // 替换系统的 tabBar
-
- self.customTabBarView = [[MOCustomTabBarView alloc] initWithFrame:self.tabBar.bounds];
- self.customTabBarView.delegate = self;
- CGRect mainFrame = self.customTabBarView.frame;
- self.customTabBarView.frame = mainFrame;
- [customTabBar addSubview:self.customTabBarView];
- customTabBar.customTabBarView = self.customTabBarView;
-
- customTabBar.backgroundImage = [UIImage new];
- customTabBar.shadowImage = [UIImage new];
- customTabBar.backgroundColor = [UIColor clearColor];
- }
- - (void)addTabbarChildViewControllers{
- UINavigationController *squareNav = [self setUpChildController:self.squareVC];
- [self addChildViewController:squareNav];
-
- UINavigationController *exploreNav = [self setUpChildController:self.exploreVC];
- [self addChildViewController:exploreNav];
-
- UINavigationController *infomationNav = [self setUpChildController:self.infomationVC];
- [self addChildViewController:infomationNav];
-
- UINavigationController *mineNav = [self setUpChildController:self.mineVC];
- [self addChildViewController:mineNav];
- }
- - (void)toResetSetupTabbar{
-
- [self toResetTabbar];
-
- //登录IM
- [self toLoginIM];
- if(!self.isNormalOpen){//是否是已登录的第一次打开
- //检查可能需要的弹窗
- [self mayBeShowAlertAction];
- }
- else{
- //已登录的第一次打开
- //调用个人信息接口, 一些装饰类的数据可能需要刷新 (个人信息)
- [self getHttpDataAboutUserInfo];
- }
-
- //获取启动页数据
- [self toGetLaunchImageAdData];
-
- [self setupBugly];
- }
- /// 重置tabbar
- - (void)toResetTabbar {
- self.selectedIndex = 0;
-
- [self.customTabBarView setSelectedIndex:0];
- NSMutableArray *newViewControllers = [NSMutableArray array];
-
- self.squareVC = nil;
- UINavigationController *squareNav = [self setUpChildController:self.squareVC];
- [newViewControllers addObject:squareNav];
-
- self.exploreVC = nil;
- UINavigationController *exploreNav = [self setUpChildController:self.exploreVC];
- [newViewControllers addObject:exploreNav];
-
- self.infomationVC = nil;
- UINavigationController *infomationNav = [self setUpChildController:self.infomationVC];
- [newViewControllers addObject:infomationNav];
-
- self.mineVC = nil;
- UINavigationController *mineNav = [self setUpChildController:self.mineVC];
- [newViewControllers addObject:mineNav];
-
- self.viewControllers = newViewControllers;
- }
- //有可能有弹窗的方法
- - (void)mayBeShowAlertAction{
- WEAKSELF
- [kHttpManager getGuideWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if (kCode_Success) {
- int regGuide = [data[@"data"][@"regGuide"] intValue];
- if (regGuide == 1) {
- MOFirstInfoSetVC *vc = [[MOFirstInfoSetVC alloc] init];
- [weakSelf loginPageActionWithVC:vc];
- } else {
- [NSObject cancelPreviousPerformRequestsWithTarget:weakSelf selector:@selector(toJudgeShowAlertView) object:nil];
- [weakSelf performSelector:@selector(toJudgeShowAlertView) withObject:nil afterDelay:0.5];
- }
- }
- }];
-
- }
- - (void)loginPageActionWithVC:(UIViewController *)vc {
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
- nav.modalPresentationStyle = UIModalPresentationFullScreen;
- [nav.navigationBar setHidden:YES];
- [self presentModalViewController:nav animated:YES];
- }
- - (void)toJudgeShowAlertView{
-
- if(self.isAgainLogin){
- self.isAgainLogin = NO;
- return;
- }
-
- //主播判断是否有直播间
- [self toGetMyLivingRoom];
-
- //检查版本
- [self toCheckAppVersion];
-
- //当前签到弹窗
- [self toGetTheSignInHttpData];
-
- //勋章弹窗
- [self toGetTheEventHttpData];
-
- //检查是否引流跳转
- [self toCheckAgentJumpRoom];
- }
- - (void)getHttpDataAboutUserInfo{
- WEAKSELF
- [kHttpManager getMeUserInfoWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- //更新个人信息偏好缓存
- [MODataManager saveUserInfo:data];
- }
- }];
- }
- - (void)toShowDiamondWinAlertView{
- WEAKSELF
- MODiamondWinAlertView *view = [MODiamondWinAlertView moDiamondWinAlertView];
- [view showDiamondWinAlertView];
- view.openDiamondWinBlock = ^{
- MODiaWinVC *vc = [[MODiaWinVC alloc] init];
- vc.hidesBottomBarWhenPushed = YES;
- [weakSelf.selectedViewController pushViewController:vc animated:YES];
- };
- }
- - (void)ChangeNeedShowAlert{
-
- //签到弹窗, 切换账号后, 也需要弹出
- [self toShowAlertWithChangeAccount];
-
- //检查版本
- [self toCheckAppVersion];
- }
- - (void)toShowAlertWithChangeAccount{
- [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(toGetTheSignInHttpData) object:nil];
- [self performSelector:@selector(toGetTheSignInHttpData) withObject:nil afterDelay:0.5];
- }
- static BOOL signInTag = NO;
- - (void)toGetTheSignInHttpData{
-
- if(signInTag){
- return;
- }
-
-
- signInTag = YES;
- [self performSelector:@selector(updateTheSignInTag) withObject:nil afterDelay:2.0];
-
- //弹窗管理器接口 (首充/签到弹窗)
- [self toShowTheDiamondWinnerView];
- }
- - (void)updateTheSignInTag{
- signInTag = NO;
- }
- - (void)toShowTheDiamondWinnerView{
- WEAKSELF
- [kHttpManager getTheDialogInfoWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MOAlertBaseData *baseData = [MOAlertBaseData modelObjectWithDictionary:data[@"data"]];
- if(baseData.actBigWinner){
- [weakSelf toShowDiamondWinAlertView];
- }
-
- [MOSvgaSourceManage shareManager].floatings = [baseData.floatings copy];
- SendObjNotification(@"MOFirstRecharge_UpdataView", baseData.floatings);
- self.floatingsArr = baseData.floatings;
- [weakSelf toShowAlertManageViewWith:baseData.dialogsData];
- }
- else{
- MOLogV(@"getTheDialogInfoWithParams 接口报错了");
-
- #if kAPP_Environment == 1
- #elif kAPP_Environment == 2
- kShowNetError(data)
- #endif
-
- }
- }];
- }
- - (void)toShowAlertManageViewWith:(NSArray *)codesArr{
- if(codesArr.count == 0){
- return;
- }
- NSMutableArray *dataArr = [NSMutableArray array];
-
- for (MODialogsData *object in codesArr) {
- if(object.type > 0 && object.type < 4){
- [dataArr addObject:object];
- } else if (object.type == 4) {//显示新手礼包弹窗
- [[MODataCache sharedYYCache] setObject:object forKey:kNewUserGiftPack];
-
- SendObjNotification(@"kNotification_ShowNewComerGiftView", object)
- return;
- }
- }
-
- NSArray *sortedArray = [dataArr sortedArrayUsingComparator:^NSComparisonResult(MODialogsData * obj1, MODialogsData * obj2) {
- if (obj1.type == 3 && obj2.type != 3) {
- return NSOrderedAscending; // obj1排在前面
- }
- if (obj2.type == 3 && obj1.type != 3) {
- return NSOrderedDescending; // obj2排在前面
- }
-
- if (obj1.type == 1 && obj2.type != 1) {
- return NSOrderedAscending; // obj1排在前面
- }
- if (obj2.type == 1 && obj1.type != 1) {
- return NSOrderedDescending; // obj2排在前面
- }
-
- return NSOrderedSame; // 如果 type 相等,保持原顺序
- }];
- SendObjNotification(@"Noti_MOActivityManageView", sortedArray)
-
- }
- - (void)toShowSignInAlertViewWith:(MOSignBaseData *)data{
- WEAKSELF
- MOSignInAlertView *view = [MOSignInAlertView moSignInAlertView];
- view.isGet = NO;
- view.baseData = data;
- view.toTaskWebBlock = ^{
- MOWebViewController *vc = [[MOWebViewController alloc] init];
- NSString *urlStr = [NSString stringWithFormat:@"%@/#/taskCenter?tagName=dailyTasks",kNetPath_Web_Base];
- vc.webUrl = [NSURL URLWithString:urlStr];
- vc.hidesBottomBarWhenPushed = YES;
- [weakSelf.selectedViewController pushViewController:vc animated:YES];
- };
- [view showSignInAlertView];
- }
- - (UINavigationController *)setUpChildController:(UIViewController *)childVC{
- UINavigationController *childVcNvc = [[UINavigationController alloc]initWithRootViewController:childVC];
- childVcNvc.navigationBar.tintColor = [UIColor whiteColor];
- childVcNvc.navigationBar.translucent = NO;
-
- NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
- textAttrs[NSForegroundColorAttributeName] = [MOTools colorWithHexString:@"#333333" alpha:1.0];
- textAttrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:17];
- [childVcNvc.navigationBar setTitleTextAttributes:textAttrs];
-
- return childVcNvc;
- }
- - (void)toCheckAgentJumpRoom {
- if (!GetToken) return;
-
- NSString *roomId = (NSString *)[[MODataCache sharedYYCache] objectForKey:kAgentJumpRoomId];
- if (roomId.length == 0) {
- return;
- }
- if ([self isInLiveRoom]) {
- return;
- }
-
- // 移除记录
- [[MODataCache sharedYYCache] removeObjectForKey:kAgentJumpRoomId];
- [MOShowAgoraKitManager shareManager].isFirstShow = YES;
- MOLiveList *model = [[MOLiveList alloc] init];
- model.id = roomId;
- MOShowLivePagesVC *vc = [[MOShowLivePagesVC alloc] init];
- vc.userType = MOShowLiveAudienceType;
- vc.roomList = @[model].mutableCopy;
- vc.focusIndex = 0;
-
- vc.hidesBottomBarWhenPushed = YES;
- [self.selectedViewController pushViewController:vc animated:YES];
- }
- #pragma mark - CustomTabBarViewDelegate
- - (void)customTabBarDidSelectIndex:(NSInteger)index {
- [self.customTabBarView setSelectedIndex:index];
-
- if(index == self.selectedIndex){
- if(index == 0){
- SendNotification(@"MOSquareListVC_Refresh");
- }
- else if (index == 1){
- SendNotification(@"MOExploreVC_Refresh");
- }
- }
-
- //正常点击
- self.selectedIndex = index;
-
- if(index!= 3){
- [[MORefreshViewManage shareManager] setNeedRefreshWithCode:@"MOMineVC"];
- }
- }
- - (void)showTabbarWithAnimation:(BOOL)animation {
-
- CGFloat duration = animation ? 0.5 : 0;
- // 如果已有动画,则取消当前动画
- [self.propertyAnimator stopAnimation:YES];
-
- // 创建一个新的动画
- self.propertyAnimator = [[UIViewPropertyAnimator alloc] initWithDuration:duration curve:UIViewAnimationCurveEaseInOut animations:^{
- self.customTabBarView.alpha = 1.0;
- self.customTabBarView.transform = CGAffineTransformIdentity;
- }];
-
- // 开始动画
- [self.propertyAnimator startAnimation];
- }
- - (void)hideTabbarWithAnimation:(BOOL)animation {
-
- CGFloat duration = animation ? 0.5 : 0;
-
- // 如果已有动画,则取消当前动画
- [self.propertyAnimator stopAnimation:YES];
-
- // 创建一个新的动画
- self.propertyAnimator = [[UIViewPropertyAnimator alloc] initWithDuration:duration curve:UIViewAnimationCurveEaseInOut animations:^{
- self.customTabBarView.alpha = 0.0;
- self.customTabBarView.transform = CGAffineTransformMakeTranslation(0, 30);
- }];
-
- // 开始动画
- [self.propertyAnimator startAnimation];
- }
- - (void)toOpenTheLiveRoom{
- [self.squareVC toOpenTheLiveRoom];
- }
- #pragma mark - Lazy
- - (MOSquareListVC *)squareVC{
- if(_squareVC == nil){
- _squareVC = [[MOSquareListVC alloc] init];
- _squareVC.homePageShowBlock = ^{
- [[MOSvgaSourceManage shareManager] toGetTheBaseResources];
- };
- }
-
- return _squareVC;
- }
- - (MOExploreVC *)exploreVC{
- if(_exploreVC == nil){
- _exploreVC = [[MOExploreVC alloc] init];
- }
-
- return _exploreVC;
- }
- - (MOInfomationVC *)infomationVC{
- if(_infomationVC == nil){
- _infomationVC = [[MOInfomationVC alloc] init];
- }
-
- return _infomationVC;
- }
- - (MOMineVC *)mineVC{
- if(_mineVC == nil){
- _mineVC = [[MOMineVC alloc] init];
- }
-
- return _mineVC;
- }
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [[V2TIMManager sharedInstance] removeConversationListener:self];
- }
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
- return UIInterfaceOrientationMaskPortrait;
- }
- - (void)toCheckAppVersion{
- if (self.versionView.superview) {//防止重复弹出
- return;
- }
-
- [kHttpManager toCheckAppVersionWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- NSDictionary *baseDict = [MODataManager objectOrNilForKey:@"data" fromDictionary:data];
- if(baseDict){
- MOVersionModel *model = [MOVersionModel modelWithJSON:baseDict];
- MONewVersionView *view = [MONewVersionView moNewVersionView];
- view.model = model;
- [view showNewVersionView];
- self.versionView = view;
- }
- }
- else{
-
- #if kAPP_Environment == 1
- #elif kAPP_Environment == 2
- kShowNetError(data)
- #endif
-
- }
- }];
- }
- - (void)toGetLaunchImageAdData{
- //1=首页图片,2=直播间图片,3=New页图片,4=启动页图片,5=开播页图片,6=语音列表图片
- NSDictionary *dict = @{@"category":@(4)};
- [kHttpManager getBaseBannerListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MOBannerData *baseModel = [MOBannerData modelObjectWithDictionary:data[@"data"]];
- [[MODataCache sharedYYCache] setObject:baseModel forKey:kFirstLaunchInfo];
- }
- else{
- #if kAPP_Environment == 1
- #elif kAPP_Environment == 2
- kShowNetError(data)
- #endif
- }
- }];
- }
- #pragma mark - 升级/勋章
- - (void)toGetTheEventHttpData{
-
- return;
- NSDictionary *basePage = @{@"size":@(100),@"next":@""};
- NSDictionary *baseDict = @{@"page":basePage};
-
- [kHttpManager toGetUserEventListWithParams:baseDict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MOEventData *baseData = [MOEventData modelObjectWithDictionary:data[@"data"]];
-
- MOEventList *showModel;
- if(baseData.eventList.count > 0){
- showModel = baseData.eventList.lastObject;
-
- MOGetShowView *view = [MOGetShowView moGetShowView];
- view.viewModel = showModel;
- [view showGetShowView];
- }
- }
- else{
- MOLogV(@"toGetTheEventHttpData 接口报错了");
- }
- }];
- }
- - (void)setupBugly{
- #if !TARGET_IPHONE_SIMULATOR
- BuglyConfig * config = [[BuglyConfig alloc] init];
- //日志级别
-
- config.blockMonitorEnable = YES;
- config.blockMonitorTimeout = 3.5;
-
-
- #if kAPP_Environment == 1
- config.reportLogLevel = BuglyLogLevelError;
- [Bugly startWithAppId:KBuglyKeyId config:config];
- #elif kAPP_Environment == 2
- config.reportLogLevel = BuglyLogLevelVerbose;
- [Bugly startWithAppId:KBuglyKeyId developmentDevice:YES config:config];
- #endif
-
- NSString *userNo = GetUserNo;
- NSString *userName = GetNickName;
- if(userName.length == 0){
- userName = [UIDevice currentDevice].name;
- }
-
- if(userNo.length == 0){
- userNo = userName;
- }
-
- [Bugly setUserIdentifier:userNo];
- #endif
-
- }
- @end
|