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"
|
2025-08-12 13:56:09 +08:00
|
|
|
|
#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 {
|
|
|
|
|
|
//设置SDK参数,app生命周期内调用一次即可
|
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];
|
2025-08-12 13:56:09 +08:00
|
|
|
|
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]]) {
|
|
|
|
|
|
|
|
|
|
|
|
// 这个获取的是iCloud记录的账号密码,需要输入框支持iOS 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
|