Files
featherVoice/QXLive/Other/AppDelegate+Login.m

301 lines
11 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// AppDelegate+Login.m
// QXLive
//
// Created by on 2025/5/8.
//
#import "AppDelegate+Login.h"
#import "ATAuthSDK/TXCommonHandler.h"
#import "ATAuthSDK/PNSReturnCode.h"
#import "TUILogin.h"
//#import <RTCRoomEngine/TUIRoomEngine.h>
#import <WXApi.h>
#import "QXLoginNetwork.h"
#import "QXMineNetwork.h"
#import "QXMessageServices.h"
#import "QXManagerMqtt.h"
#import "OpenUDID.h"
2025-10-30 00:45:15 +08:00
#import "TUIChatConfig.h"
2025-08-08 10:49:36 +08:00
@implementation AppDelegate (Login)
-(void)configThirdPartLogin{
BOOL result = [WXApi registerApp:WechatAppId universalLink:WechatUniversalLink];
if (result) {
NSLog(@"微信注册成功");
}else{
NSLog(@"微信注册失败");
}
[self ATAuthSDK];
[self tencentLogin];
}
- (void)ATAuthSDK {
//SDKapp
2025-10-30 00:45:15 +08:00
///
#if DEVELOPENT == 1
[TUIChatConfig defaultConfig].msgNeedReadReceipt = NO;
#else
[TUIChatConfig defaultConfig].msgNeedReadReceipt = YES;
#endif
[TUIChatConfig defaultConfig].enableWelcomeCustomMessage = NO;
2025-08-08 10:49:36 +08:00
[[TXCommonHandler sharedInstance] setAuthSDKInfo:AuthSDKKey complete:^(NSDictionary * _Nonnull resultDic) {
if ([PNSCodeSuccess isEqualToString:[resultDic objectForKey:@"resultCode"]]) {
//success
[QXGlobal shareGlobal].canOneLogin = YES;
}else{
[QXGlobal shareGlobal].canOneLogin = NO;
}
}];
}
-(void)tencentLogin{
if (![QXGlobal shareGlobal].isLogin) {
return;
}
NSString *userId = [QXGlobal shareGlobal].loginModel.user_id;
NSString *tencent_im = [QXGlobal shareGlobal].loginModel.tencent_im;
MJWeakSelf
[TUILogin login:TencentIMID userID:[NSString stringWithFormat:@"u%@",userId] userSig:tencent_im succ:^{
QXLOG(@"腾讯IM登录成功");
[weakSelf getUnReadMessage];
[[NSNotificationCenter defaultCenter] postNotificationName:noticeTencentLogin object:nil];
[TIMPushManager addPushListener:self];
[[V2TIMManager sharedInstance] addConversationListener:self];
[self configAppPush];
[self getHomeMessage];
[V2TIMManager.sharedInstance addIMSDKListener:self];
} fail:^(int code, NSString *msg) {
QXLOG(@"腾讯IM登录失败-code-%d--msg-%@",code,msg);
}];
// [TUIRoomEngine loginWithSDKAppId:TencentIMID userId:userId userSig:tencent_im onSuccess:^{
// QXLOG(@"腾讯语音登录成功");
// } onError:^(TUIError code, NSString * _Nonnull message) {
// QXLOG(@"腾讯语音登录失败");
// }];
[[QXLocationManager shareManager] startLoction];
[QXLocationManager shareManager].delegate = self;
[self getUserInfo];
NSString *clientId = [OpenUDID value];
[[QXManagerMqtt sharedInstance] bindWithUserName:@"public" password:@"" cliendId:clientId isSSL:NO];
2025-08-08 10:49:36 +08:00
}
2025-10-20 09:43:10 +08:00
-(void)onConnectSuccess{
// showToast(@"腾讯重连服务器成功");
// NSLog(@"腾讯重连服务器成功");
if ([QXGlobal.shareGlobal.roomId isExist]) {
return;
}
[QXMineNetwork roomUserReconnectWithRoomId:QXGlobal.shareGlobal.roomId successBlock:^(NSDictionary * _Nonnull dict) {
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
}];
}
-(void)onConnecting{
// NSLog(@"腾讯重连服务器中");
// showToast(@"腾讯重连服务器中");
}
-(void)onConnectFailed:(int)code err:(NSString *)err{
// showToast(err);
// NSLog(@"腾讯连接服务器失败code----%d---err%@",code,err);
}
2025-08-08 10:49:36 +08:00
-(void)onKickedOffline{
MJWeakSelf
QXBaseNavigationController *na = (QXBaseNavigationController *)KEYWINDOW.rootViewController;;
UIAlertController *al = [UIAlertController alertControllerWithTitle:@"您的账号已在别处登录,请确认密码是否已经泄露" message:@"" preferredStyle:(UIAlertControllerStyleAlert)];
[al addAction:[UIAlertAction actionWithTitle:@"好的" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
[weakSelf takeOff];
}]];
[na presentViewController:al animated:YES completion:nil];
}
-(void)takeOff{
if(QXGlobal.shareGlobal.roomId.length > 0){
[[QXGlobal shareGlobal] quitRoomWithRoomId:QXGlobal.shareGlobal.roomId];
}
self.tabbarVC.selectedIndex = 3;
QXBaseNavigationController *tabbarNa = (QXBaseNavigationController *)self.tabbarVC.selectedViewController;
[tabbarNa popToRootViewControllerAnimated:NO];
QXBaseNavigationController *na = (QXBaseNavigationController *)KEYWINDOW.rootViewController;;
[na popToRootViewControllerAnimated:YES];
MJWeakSelf
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[QXGlobal shareGlobal] logOut];
});
}
-(void)getUnReadMessage{
MJWeakSelf
[[V2TIMManager sharedInstance] getTotalUnreadMessageCount:^(UInt64 totalCount) {
// totalCount
// UI
weakSelf.tabbarVC.messageUnReadNumber = totalCount;
} fail:^(int code, NSString *desc) {
//
}];
}
-(void)getHomeMessage{
MJWeakSelf
[QXMessageServices getHomeMessageSuccessBlock:^(QXMessageModel * _Nonnull model) {
weakSelf.tabbarVC.systemUnreadNumber = model.system_no_read_count.integerValue + model.announcement_read_count.integerValue;
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
}];
}
-(void)configAppPush{
// const int sdkAppId = sdkAppId;
// static const NSString *appKey = @"客户端密钥";
[TIMPushManager registerPush:TencentIMID appKey:TencentIMSecret succ:^(NSData * _Nonnull deviceToken) {
QXLOG(@"注册push成功");
} fail:^(int code, NSString * _Nonnull desc) {
QXLOG(@"注册push失败--%d--%@",code,desc);
}];
}
-(void)getUserInfo{
[QXMineNetwork getMineInfoSuccessBlock:^(QXUserModel * _Nonnull userModel) {
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
}];
}
-(void)locationSuccessWithCity:(NSString *)city province:(NSString *)province area:(NSString *)area address:(NSString *)address{
[[QXLocationManager shareManager] stopLoction];
NSString *ip = [NSString stringWithFormat:@"%@,%@,%@",province,city,area];
[QXLoginNetwork updateUserIp:ip successBlock:^(id _Nonnull responseObject) {
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
}];
}
- (void)onTotalUnreadMessageCountChanged:(UInt64)totalUnreadCount {
self.tabbarVC.messageUnReadNumber = totalUnreadCount;
UInt64 unread = self.tabbarVC.systemUnreadNumber + totalUnreadCount;
self.tabbarVC.unReadNumber = unread;
[[NSNotificationCenter defaultCenter] postNotificationName:noticeUnreadNumberDidChanged object:[NSNumber numberWithLong:totalUnreadCount]];
}
#pragma mark - ID
- (void)authorizationAppleID {
if (@available(iOS 13.0, *)) {
// Apple ID
ASAuthorizationAppleIDProvider * appleIDProvider = [[ASAuthorizationAppleIDProvider alloc] init];
// AppleID
ASAuthorizationAppleIDRequest * authAppleIDRequest = [appleIDProvider createRequest];
NSMutableArray <ASAuthorizationRequest *> * array = [NSMutableArray arrayWithCapacity:2];
if (authAppleIDRequest) {
[array addObject:authAppleIDRequest];
}
NSArray <ASAuthorizationRequest *> * requests = [array copy];
// ASAuthorizationAppleIDProvider
ASAuthorizationController * authorizationController = [[ASAuthorizationController alloc] initWithAuthorizationRequests:requests];
//
authorizationController.delegate = self;
//
authorizationController.presentationContextProvider = self;
//
[authorizationController performRequests];
} else {
//
NSLog(@"系统不支持Apple登录");
}
}
#pragma mark - ASAuthorizationControllerDelegate
//
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization API_AVAILABLE(ios(13.0)) {
if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) {
ASAuthorizationAppleIDCredential * credential = (ASAuthorizationAppleIDCredential *)authorization.credential;
// App
NSString * userID = credential.user;
// //
// NSPersonNameComponents * fullName = credential.fullName;
NSString * email = credential.email;
// // 使
// NSString * authorizationCode = [[NSString alloc] initWithData:credential.authorizationCode encoding:NSUTF8StringEncoding];
// NSString * identityToken = [[NSString alloc] initWithData:credential.identityToken encoding:NSUTF8StringEncoding];
NSString *tokenStr = [@"ios" stringByAppendingString:userID];
QXLOG(@"apple-tokenStr%@",tokenStr);
// [self rquestThirdLogin:tokenStr withEmail:email];
[[NSNotificationCenter defaultCenter] postNotificationName:noticeAppleLogin object:tokenStr];
} else if ([authorization.credential isKindOfClass:[ASPasswordCredential class]]) {
// iCloudiOS 12
// 使
ASPasswordCredential * passwordCredential = (ASPasswordCredential *)authorization.credential;
//
NSString * user = passwordCredential.user;
//
//
NSString * password = passwordCredential.password;
NSLog(@"userID: %@", user);
NSLog(@"password: %@", password);
} else {
}
}
#pragma mark - ASAuthorizationControllerPresentationContextProviding
- (ASPresentationAnchor)presentationAnchorForAuthorizationController:(ASAuthorizationController *)controller API_AVAILABLE(ios(13.0)) {
return self.window;
}
@end