2025-08-14 10:07:49 +08:00
|
|
|
//
|
|
|
|
|
// QXGlobal.m
|
|
|
|
|
// TrucksProject
|
|
|
|
|
//
|
|
|
|
|
// Created by 党凯 on 2020/6/30.
|
|
|
|
|
// Copyright © 2020 党凯. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "QXGlobal.h"
|
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
|
#import "QXLoginViewController.h"
|
|
|
|
|
#import "QXBaseNavigationController.h"
|
|
|
|
|
#import "TUILogin.h"
|
|
|
|
|
#import "QXChatViewController.h"
|
|
|
|
|
#import "QXRoomViewController.h"
|
|
|
|
|
#import "QXMineNetwork.h"
|
|
|
|
|
#import "QXGiftPlayerManager.h"
|
|
|
|
|
#import "QXAgoraEngine.h"
|
|
|
|
|
#import "QXRoomMessageManager.h"
|
|
|
|
|
#import "QXTimer.h"
|
|
|
|
|
#import <TIMPush/TIMPushManager.h>
|
|
|
|
|
#import "QXManagerMqtt.h"
|
|
|
|
|
|
|
|
|
|
@interface QXGlobal()
|
|
|
|
|
@property (nonatomic,assign)BOOL isLogin;
|
|
|
|
|
@property (nonatomic,strong)NSString *roomId;
|
|
|
|
|
|
2025-09-19 11:38:43 +08:00
|
|
|
@property (nonatomic,assign)BOOL isClickJoinRoom;
|
|
|
|
|
|
2025-08-14 10:07:49 +08:00
|
|
|
@property (nonatomic,strong)QXTimer *timer;
|
|
|
|
|
@property (nonatomic,assign)NSInteger taskTime;
|
|
|
|
|
@end
|
|
|
|
|
@implementation QXGlobal
|
|
|
|
|
+ (instancetype)shareGlobal {
|
|
|
|
|
static QXGlobal *global = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
global = [[self alloc] init];
|
|
|
|
|
global.isShowLoginVC = NO;
|
|
|
|
|
});
|
|
|
|
|
return global;
|
|
|
|
|
}
|
|
|
|
|
-(UIWindow *)getKeyWindow{
|
|
|
|
|
AppDelegate*appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
|
|
|
|
|
UIWindow *window = appDelegate.window;
|
|
|
|
|
return window;
|
|
|
|
|
}
|
|
|
|
|
-(void)logOut{
|
|
|
|
|
[TUILogin logout:^{
|
|
|
|
|
QXLOG(@"腾讯im退出登录成功");
|
|
|
|
|
} fail:^(int code, NSString * _Nullable msg) {
|
|
|
|
|
QXLOG(@"腾讯im退出登录失败");
|
|
|
|
|
}];
|
|
|
|
|
self.isLogin = NO;
|
|
|
|
|
[self removeLocalData];
|
|
|
|
|
[self removeMemory];
|
|
|
|
|
AppDelegate *appdelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
|
|
|
|
|
/// 移除推送监听
|
|
|
|
|
[TIMPushManager removePushListener:appdelegate];
|
|
|
|
|
/// 移除会话监听
|
|
|
|
|
[[V2TIMManager sharedInstance] removeConversationListener:appdelegate];
|
|
|
|
|
[TIMPushManager unRegisterPush:^{
|
|
|
|
|
//success
|
|
|
|
|
} fail:^(int code, NSString * _Nonnull desc) {
|
|
|
|
|
//error
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
if (self.isShowLoginVC == YES) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QXLoginViewController *vc = [[QXLoginViewController alloc] init];
|
|
|
|
|
QXBaseNavigationController *na = [[QXBaseNavigationController alloc] initWithRootViewController:vc];
|
|
|
|
|
na.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
|
|
|
[self.getKeyWindow.rootViewController presentViewController:na animated:YES completion:nil];
|
|
|
|
|
self.isShowLoginVC = YES;
|
|
|
|
|
/// 断开mqtt连接
|
|
|
|
|
[[QXManagerMqtt sharedInstance] disconnect];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
-(void)saveLoginData:(NSString *)userInfoJson{
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:userInfoJson forKey:kUserLoginData];
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
|
}
|
|
|
|
|
-(void)updateUserInfoWithMolde:(QXLoginModel *)loginModel{
|
|
|
|
|
NSString *jsonStr = [loginModel yy_modelToJSONString];
|
|
|
|
|
[self saveLoginData:jsonStr];
|
|
|
|
|
}
|
|
|
|
|
//-(void)setLoginModel:(QXLoginModel *)loginModel{
|
|
|
|
|
// _loginModel = loginModel;
|
|
|
|
|
// if (loginModel == nil) {
|
|
|
|
|
// self.isLogin = NO;
|
|
|
|
|
// }else{
|
|
|
|
|
// self.isLogin = YES;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
-(BOOL)isRealName{
|
|
|
|
|
return [QXGlobal shareGlobal].loginModel.auth == 1;
|
|
|
|
|
}
|
|
|
|
|
-(QXLoginModel *)loginModel{
|
|
|
|
|
if (!_loginModel) {
|
|
|
|
|
NSString *jsonStr = [[NSUserDefaults standardUserDefaults] objectForKey:kUserLoginData];
|
|
|
|
|
if (jsonStr.length > 0) {
|
|
|
|
|
_loginModel = [QXLoginModel yy_modelWithJSON:jsonStr];
|
|
|
|
|
self.isLogin = YES;
|
|
|
|
|
}else{
|
|
|
|
|
_loginModel = nil;
|
|
|
|
|
self.isLogin = NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return _loginModel;
|
|
|
|
|
}
|
|
|
|
|
-(void)toLogin{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
-(BOOL)isLogin{
|
|
|
|
|
NSString *jsonStr = [[NSUserDefaults standardUserDefaults] objectForKey:kUserLoginData];
|
|
|
|
|
return jsonStr.length > 0;
|
|
|
|
|
}
|
|
|
|
|
-(void)removeLocalData{
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kUserLoginData];
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
|
}
|
|
|
|
|
-(void)removeMemory{
|
|
|
|
|
QXGlobal.shareGlobal.loginModel = nil;
|
|
|
|
|
}
|
|
|
|
|
-(void)showView:(UIView *)view popType:(PopViewType)popType tapDismiss:(BOOL)tapDismiss finishBlock:(showFinishBlock)finishBlock{
|
|
|
|
|
self.alertViewController = [[QXAlertViewController alloc] init];
|
|
|
|
|
self.alertViewController.popType = popType;
|
|
|
|
|
self.alertViewController.alertView = view;
|
|
|
|
|
self.alertViewController.tapDismiss = tapDismiss;
|
|
|
|
|
self.alertViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
|
|
|
[[QXGlobal shareGlobal].getKeyWindow.rootViewController presentViewController:self.alertViewController animated:NO completion:finishBlock];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)showView:(UIView *)view controller:(UIViewController*)controller popType:(PopViewType)popType tapDismiss:(BOOL)tapDismiss finishBlock:(showFinishBlock)finishBlock{
|
|
|
|
|
self.alertViewController = [[QXAlertViewController alloc] init];
|
|
|
|
|
self.alertViewController.popType = popType;
|
|
|
|
|
self.alertViewController.alertView = view;
|
|
|
|
|
self.alertViewController.tapDismiss = tapDismiss;
|
|
|
|
|
self.alertViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
|
|
|
[controller presentViewController:self.alertViewController animated:NO completion:finishBlock];
|
|
|
|
|
}
|
|
|
|
|
-(void)hideViewBlock:(closeBlock)closeBlock{
|
|
|
|
|
[self.alertViewController hideViewFinishBlock:closeBlock];
|
|
|
|
|
}
|
|
|
|
|
-(BOOL)isOpenRecharge{
|
|
|
|
|
BOOL isOpenRecharge = [[NSUserDefaults standardUserDefaults] boolForKey:kIsOpenRecharge];
|
|
|
|
|
return isOpenRecharge;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)finishTask{
|
|
|
|
|
if (QXGlobal.shareGlobal.taskModel != nil) {
|
|
|
|
|
[QXMineNetwork dayTaskFinishedWithTaskId:QXGlobal.shareGlobal.taskModel.task_id successBlock:^(NSDictionary * _Nonnull dict) {
|
|
|
|
|
NSString *is_completed = [NSString stringWithFormat:@"%@",dict[@"is_completed"]];
|
|
|
|
|
if (is_completed.intValue == 1) {
|
|
|
|
|
QXGlobal.shareGlobal.taskModel = nil;
|
|
|
|
|
QXGlobal.shareGlobal.taskTime = 0;
|
|
|
|
|
if (self->_timer) {
|
|
|
|
|
[self->_timer invalidate];
|
|
|
|
|
self->_timer = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)chatWithUserID:(NSString *)userId nickname:(NSString *)nickname avatar:(NSString *)avatar navagationController:(UINavigationController *)navagationController{
|
|
|
|
|
QXChatViewController *vc = [[QXChatViewController alloc] init];
|
|
|
|
|
TUIChatConversationModel *data = [[TUIChatConversationModel alloc] init];
|
|
|
|
|
data.userID = [NSString stringWithFormat:@"u%@",userId];
|
|
|
|
|
data.title = nickname;
|
|
|
|
|
data.faceUrl = avatar;
|
|
|
|
|
vc.data = data;
|
|
|
|
|
[navagationController pushViewController:vc animated:YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)chatWithGroupId:(NSString *)groupId cover:(NSString *)cover name:(NSString *)name navagationController:(UINavigationController *)navagationController{
|
|
|
|
|
QXChatViewController *vc = [[QXChatViewController alloc] init];
|
|
|
|
|
TUIChatConversationModel *data = [[TUIChatConversationModel alloc] init];
|
|
|
|
|
if ([groupId containsString:@"g"]) {
|
|
|
|
|
data.groupID = groupId;
|
|
|
|
|
}else{
|
|
|
|
|
data.groupID = [NSString stringWithFormat:@"g%@",groupId];
|
|
|
|
|
}
|
|
|
|
|
data.faceUrl = cover;
|
|
|
|
|
data.title = name;
|
|
|
|
|
vc.data = data;
|
|
|
|
|
[navagationController pushViewController:vc animated:YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)joinRoomWithRoomId:(NSString *)roomId isRejoin:(BOOL)isRejoin navagationController:(UINavigationController *)navagationController{
|
|
|
|
|
if (!QXGlobal.shareGlobal.isLogin) {
|
|
|
|
|
[[QXGlobal shareGlobal] logOut];
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-09-19 11:38:43 +08:00
|
|
|
|
2025-08-14 10:07:49 +08:00
|
|
|
navagationController = (QXBaseNavigationController*)KEYWINDOW.rootViewController;
|
|
|
|
|
// navagationController.interactivePopGestureRecognizer.enabled = NO;
|
|
|
|
|
if (_miniView) {
|
|
|
|
|
[_miniView removeFromSuperview];
|
|
|
|
|
_miniView = nil;
|
|
|
|
|
}
|
|
|
|
|
if ([roomId isEqualToString:self.roomId]) {
|
|
|
|
|
if ([navagationController.viewControllers containsObject:self.roomVC]) {
|
|
|
|
|
return;
|
|
|
|
|
}else{
|
2025-09-19 11:38:43 +08:00
|
|
|
[UIApplication sharedApplication].idleTimerDisabled = YES;
|
2025-08-14 10:07:49 +08:00
|
|
|
self.roomVC.hidesBottomBarWhenPushed = YES;
|
2025-09-22 14:58:13 +08:00
|
|
|
[self.roomVC playHWDMP4];
|
2025-08-14 10:07:49 +08:00
|
|
|
[navagationController pushViewController:self.roomVC animated:YES];
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (self.roomId && ![self.roomId isEqualToString:roomId]) {
|
|
|
|
|
[self quitRoomWithRoomId:self.roomId];
|
|
|
|
|
}
|
2025-09-19 11:38:43 +08:00
|
|
|
[UIApplication sharedApplication].idleTimerDisabled = YES;
|
|
|
|
|
MJWeakSelf
|
2025-08-14 10:07:49 +08:00
|
|
|
if (isRejoin) {
|
|
|
|
|
if (self.roomVC!=nil) {
|
2025-09-22 14:58:13 +08:00
|
|
|
[self.roomVC playHWDMP4];
|
2025-08-14 10:07:49 +08:00
|
|
|
self.roomVC.hidesBottomBarWhenPushed = YES;
|
|
|
|
|
[navagationController pushViewController:self.roomVC animated:YES];
|
|
|
|
|
}else{
|
2025-09-19 11:38:43 +08:00
|
|
|
if (weakSelf.isClickJoinRoom) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// showLoadingInView(KEYWINDOW)
|
|
|
|
|
weakSelf.isClickJoinRoom = YES;
|
2025-09-22 14:58:13 +08:00
|
|
|
[[QXRoomMessageManager shared] joinGroupWithRoomId:roomId];
|
2025-09-19 11:38:43 +08:00
|
|
|
[QXMineNetwork joinRoomWithRoomId:roomId successBlock:^(QXRoomModel * _Nonnull roomModel) {
|
|
|
|
|
// hideLoadingInView(KEYWINDOW)
|
|
|
|
|
// roomModel.room_info.pk_room_id = @"33";
|
|
|
|
|
weakSelf.isClickJoinRoom = NO;
|
|
|
|
|
weakSelf.roomVC = [[QXRoomViewController alloc] init];
|
|
|
|
|
weakSelf.roomVC.roomId = roomId;
|
|
|
|
|
weakSelf.roomVC.isReJoin = isRejoin;
|
|
|
|
|
weakSelf.roomId = roomId;
|
|
|
|
|
weakSelf.roomVC.roomModel = roomModel;
|
|
|
|
|
weakSelf.roomVC.hidesBottomBarWhenPushed = YES;
|
|
|
|
|
[navagationController pushViewController:weakSelf.roomVC animated:YES];
|
|
|
|
|
weakSelf.roomId = roomId;
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
showToast(msg);
|
|
|
|
|
// hideLoadingInView(KEYWINDOW)
|
|
|
|
|
weakSelf.isClickJoinRoom = NO;
|
|
|
|
|
}];
|
2025-08-14 10:07:49 +08:00
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if ([roomId isEqualToString:self.roomVC.roomId]) {
|
2025-09-22 14:58:13 +08:00
|
|
|
[self.roomVC playHWDMP4];
|
2025-08-14 10:07:49 +08:00
|
|
|
[navagationController pushViewController:self.roomVC animated:YES];
|
|
|
|
|
}else{
|
2025-09-19 11:38:43 +08:00
|
|
|
// showLoadingInView(KEYWINDOW)
|
|
|
|
|
if (weakSelf.isClickJoinRoom) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
weakSelf.isClickJoinRoom = YES;
|
2025-09-22 14:58:13 +08:00
|
|
|
[[QXRoomMessageManager shared] joinGroupWithRoomId:roomId];
|
2025-09-19 11:38:43 +08:00
|
|
|
[QXMineNetwork joinRoomWithRoomId:roomId successBlock:^(QXRoomModel * _Nonnull roomModel) {
|
|
|
|
|
// hideLoadingInView(KEYWINDOW)
|
|
|
|
|
// roomModel.room_info.pk_room_id = @"33";
|
|
|
|
|
weakSelf.isClickJoinRoom = NO;
|
|
|
|
|
weakSelf.roomVC = [[QXRoomViewController alloc] init];
|
|
|
|
|
weakSelf.roomVC.roomId = roomId;
|
|
|
|
|
weakSelf.roomVC.isReJoin = isRejoin;
|
|
|
|
|
weakSelf.roomId = roomId;
|
|
|
|
|
weakSelf.roomVC.roomModel = roomModel;
|
|
|
|
|
weakSelf.roomVC.hidesBottomBarWhenPushed = YES;
|
|
|
|
|
[navagationController pushViewController:weakSelf.roomVC animated:YES];
|
|
|
|
|
weakSelf.roomId = roomId;
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
weakSelf.isClickJoinRoom = NO;
|
|
|
|
|
showToast(msg);
|
|
|
|
|
// hideLoadingInView(KEYWINDOW)
|
|
|
|
|
}];
|
2025-08-14 10:07:49 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (QXGlobal.shareGlobal.taskModel != nil) {
|
|
|
|
|
/// 是否带有每日任务
|
|
|
|
|
if (QXGlobal.shareGlobal.taskModel.task_id.intValue == 9) {
|
|
|
|
|
/// 是计时任务
|
|
|
|
|
if (_timer == nil) {
|
|
|
|
|
_timer = [QXTimer scheduledTimerWithTimeInterval:1 repeats:YES queue:dispatch_get_main_queue() block:^{
|
|
|
|
|
QXGlobal.shareGlobal.taskTime++;
|
|
|
|
|
if (QXGlobal.shareGlobal.taskTime%60 == 0) {
|
|
|
|
|
[[QXGlobal shareGlobal] finishTask];
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-(void)quitRoomWithRoomId:(NSString *)roomId{
|
2025-09-19 11:38:43 +08:00
|
|
|
[UIApplication sharedApplication].idleTimerDisabled = NO;
|
2025-08-14 10:07:49 +08:00
|
|
|
/// 移除特效
|
|
|
|
|
[[QXGiftPlayerManager shareManager] destroyEffectSvga];
|
|
|
|
|
/// 退出声网
|
|
|
|
|
[[QXAgoraEngine sharedEngine] leaveChannel];
|
2025-09-19 11:38:43 +08:00
|
|
|
/// 销毁播放器
|
2025-08-14 10:07:49 +08:00
|
|
|
[[QXAgoraEngine sharedEngine] ktv_DestoryKtvPlayer];
|
2025-09-19 11:38:43 +08:00
|
|
|
/// 销毁整个声网示例
|
2025-08-14 10:07:49 +08:00
|
|
|
[[QXAgoraEngine sharedEngine] destroyEngine];
|
|
|
|
|
/// 退出直播群
|
|
|
|
|
[[QXRoomMessageManager shared] quitGroupWithRoomId:roomId];
|
2025-08-22 19:02:44 +08:00
|
|
|
if (_roomVC) {
|
2025-09-19 11:38:43 +08:00
|
|
|
/// 回收麦位视图内存
|
2025-08-22 19:02:44 +08:00
|
|
|
[_roomVC.seatContentView destroyViews];
|
2025-09-19 11:38:43 +08:00
|
|
|
/// 回收控制器内存
|
2025-09-08 08:49:04 +08:00
|
|
|
[_roomVC destroyViews];
|
2025-08-22 19:02:44 +08:00
|
|
|
}
|
2025-08-14 10:07:49 +08:00
|
|
|
self.roomId = nil;
|
|
|
|
|
_roomVC = nil;
|
|
|
|
|
/// 业务http退出
|
|
|
|
|
[QXMineNetwork quitRoomWithRoomId:roomId user_id:[QXGlobal shareGlobal].loginModel.user_id successBlock:^(NSDictionary * _Nonnull dict) {
|
|
|
|
|
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
if (_timer) {
|
|
|
|
|
[_timer invalidate];
|
|
|
|
|
_timer = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
-(void)miniRoomWithRoomId:(NSString*)roomId roomCover:(NSString*)roomCover{
|
|
|
|
|
self.miniView.roomId = self.roomId;
|
|
|
|
|
self.miniView.roomCoverImage = roomCover;
|
|
|
|
|
[self.miniView show];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(QXMiniRoomView *)miniView{
|
|
|
|
|
if (!_miniView) {
|
|
|
|
|
_miniView = [[QXMiniRoomView alloc] init];
|
|
|
|
|
}
|
|
|
|
|
return _miniView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)vibrationFeedback{
|
|
|
|
|
UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy];
|
|
|
|
|
[generator impactOccurred];
|
|
|
|
|
}
|
|
|
|
|
@end
|