提交
This commit is contained in:
288
QXLive/Base/QXGlobal.m
Normal file
288
QXLive/Base/QXGlobal.m
Normal file
@@ -0,0 +1,288 @@
|
||||
//
|
||||
// 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>
|
||||
|
||||
@interface QXGlobal()
|
||||
@property (nonatomic,assign)BOOL isLogin;
|
||||
@property (nonatomic,strong)NSString *roomId;
|
||||
|
||||
@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;
|
||||
|
||||
}
|
||||
-(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{
|
||||
self.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{
|
||||
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{
|
||||
self.roomVC.hidesBottomBarWhenPushed = YES;
|
||||
[navagationController pushViewController:self.roomVC animated:YES];
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (self.roomId && ![self.roomId isEqualToString:roomId]) {
|
||||
[self quitRoomWithRoomId:self.roomId];
|
||||
}
|
||||
if (isRejoin) {
|
||||
if (self.roomVC!=nil) {
|
||||
self.roomVC.hidesBottomBarWhenPushed = YES;
|
||||
[navagationController pushViewController:self.roomVC animated:YES];
|
||||
}else{
|
||||
self.roomVC = [[QXRoomViewController alloc] init];
|
||||
self.roomVC.roomId = roomId;
|
||||
self.roomVC.isReJoin = isRejoin;
|
||||
self.roomId = roomId;
|
||||
self.roomVC.hidesBottomBarWhenPushed = YES;
|
||||
[navagationController pushViewController:self.roomVC animated:YES];
|
||||
}
|
||||
}else{
|
||||
if ([roomId isEqualToString:self.roomVC.roomId]) {
|
||||
[navagationController pushViewController:self.roomVC animated:YES];
|
||||
}else{
|
||||
self.roomVC = [[QXRoomViewController alloc] init];
|
||||
self.roomVC.roomId = roomId;
|
||||
self.roomVC.isReJoin = isRejoin;
|
||||
self.roomId = roomId;
|
||||
self.roomVC.hidesBottomBarWhenPushed = YES;
|
||||
[navagationController pushViewController:self.roomVC animated:YES];
|
||||
}
|
||||
}
|
||||
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{
|
||||
/// 移除特效
|
||||
[[QXGiftPlayerManager shareManager] destroyEffectSvga];
|
||||
/// 退出声网
|
||||
[[QXAgoraEngine sharedEngine] leaveChannel];
|
||||
|
||||
[[QXAgoraEngine sharedEngine] ktv_DestoryKtvPlayer];
|
||||
|
||||
[[QXAgoraEngine sharedEngine] destroyEngine];
|
||||
/// 退出直播群
|
||||
[[QXRoomMessageManager shared] quitGroupWithRoomId:roomId];
|
||||
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
|
||||
Reference in New Issue
Block a user