Commit 6e731e0a8796560559d1884e2f9b1063f5611772

Authored by zhangxiaowen
1 parent 8c888279

no message

CNLiveLoginModule/Classes/Controller/CNLiveLoginController.m
@@ -14,11 +14,13 @@ @@ -14,11 +14,13 @@
14 14
15 #import "CNLiveUserAgreementManager.h" 15 #import "CNLiveUserAgreementManager.h"
16 #import "CNLiveCategory.h" 16 #import "CNLiveCategory.h"
  17 +#import "CNUserInfoManager.h"
17 18
18 #import "CNLiveLoginView.h" 19 #import "CNLiveLoginView.h"
19 #import "CNLiveThreeLoginView.h" 20 #import "CNLiveThreeLoginView.h"
20 #import "CNLiveBindingTelController.h"//绑定手机号 21 #import "CNLiveBindingTelController.h"//绑定手机号
21 #import "CNLiveCompleteInfoController.h"//修改昵称 22 #import "CNLiveCompleteInfoController.h"//修改昵称
  23 +#import "CNLiveLoginRequest.h"
22 24
23 @interface CNLiveLoginController()<CNLiveLoginViewDelegate, CNLiveThreeLoginViewDelegate> 25 @interface CNLiveLoginController()<CNLiveLoginViewDelegate, CNLiveThreeLoginViewDelegate>
24 @property (nonatomic, weak) CNLiveLoginView *loginView; 26 @property (nonatomic, weak) CNLiveLoginView *loginView;
@@ -29,6 +31,7 @@ @@ -29,6 +31,7 @@
29 @end 31 @end
30 32
31 @implementation CNLiveLoginController 33 @implementation CNLiveLoginController
  34 +
32 #pragma mark - 生命周期 35 #pragma mark - 生命周期
33 - (void)viewWillAppear:(BOOL)animated{ 36 - (void)viewWillAppear:(BOOL)animated{
34 [super viewWillAppear:animated]; 37 [super viewWillAppear:animated];
@@ -97,6 +100,13 @@ @@ -97,6 +100,13 @@
97 100
98 }else{ 101 }else{
99 // 老用户 -> home 102 // 老用户 -> home
  103 + [[CNLiveLoginRequest manager] loginTIM:CNUserShareModel.uid success:^{
  104 + // 进入tabbar
  105 +
  106 + } failed:^(int code, NSString * _Nonnull msg) {
  107 + // 错误逻辑
  108 +
  109 + }];
100 110
101 } 111 }
102 112
CNLiveLoginModule/Classes/Model/CNLiveLoginRequestModel.h renamed to CNLiveLoginModule/Classes/Model/CNLiveLoginRequest.h
1 // 1 //
2 -// CNLiveLoginRequestModel.h 2 +// CNLiveLoginRequest.h
3 // CNLiveLoginModule 3 // CNLiveLoginModule
4 // 4 //
5 // Created by 153993236@qq.com on 11/12/2019. 5 // Created by 153993236@qq.com on 11/12/2019.
@@ -9,16 +9,17 @@ @@ -9,16 +9,17 @@
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 10
11 NS_ASSUME_NONNULL_BEGIN 11 NS_ASSUME_NONNULL_BEGIN
12 -typedef void (^TIMLoginSucc)(void);  
13 -typedef void (^TIMFail)(int code, NSString * msg);  
14 12
15 -@interface CNLiveLoginRequestModel : NSObject 13 +@interface CNLiveLoginRequest : NSObject
  14 +
16 + (instancetype)manager; 15 + (instancetype)manager;
17 16
18 -- (void)getTIMLoginToken:(NSString *)identifier success:(void (^)(NSString *))success failed:(void (^)(int, NSString *))failed; 17 +- (void)getTIMLoginToken:(NSString *)identifier success:(void (^)(NSString * token))success failed:(void (^)(int code, NSString * msg))failed;
  18 +
19 19
  20 +- (void)loginTIM:(NSString *)uid success:(void (^)(void))success failed:(void (^)(int code, NSString * msg))failed;
20 21
21 -- (void)loginTIM:(NSString *)uid success:(TIMLoginSucc)success failed:(TIMFail)failed; 22 +- (void)resumeLogin;
22 23
23 @end 24 @end
24 25
CNLiveLoginModule/Classes/Model/CNLiveLoginRequestModel.m renamed to CNLiveLoginModule/Classes/Model/CNLiveLoginRequest.m
1 // 1 //
2 -// CNLiveLoginRequestModel.m 2 +// CNLiveLoginRequest.m
3 // CNLiveLoginModule 3 // CNLiveLoginModule
4 // 4 //
5 // Created by 153993236@qq.com on 11/12/2019. 5 // Created by 153993236@qq.com on 11/12/2019.
6 // Copyright (c) 2019 153993236@qq.com. All rights reserved. 6 // Copyright (c) 2019 153993236@qq.com. All rights reserved.
7 // 7 //
8 8
9 -#import "CNLiveLoginRequestModel.h" 9 +#import "CNLiveLoginRequest.h"
10 #import <UIKit/UIKit.h> 10 #import <UIKit/UIKit.h>
11 #import "QMUIKit.h" 11 #import "QMUIKit.h"
12 12
13 -#import "CNUserInfoManager.h"  
14 #import "CNLiveEnvironment.h" 13 #import "CNLiveEnvironment.h"
15 #import <CNLiveRequestBastKit/CNLiveNetworking.h> 14 #import <CNLiveRequestBastKit/CNLiveNetworking.h>
16 #import "TIMAdapter.h" 15 #import "TIMAdapter.h"
17 #import "CommonLibrary.h" 16 #import "CommonLibrary.h"
18 17
19 -@interface CNLiveLoginRequestModel() 18 +#import "NBSAppAgent.h"
  19 +#import "CNLiveBusinessTools.h"
  20 +
  21 +@interface CNLiveLoginRequest()
20 @property (nonatomic, strong) IMALoginParam *loginParam; 22 @property (nonatomic, strong) IMALoginParam *loginParam;
21 23
22 @end 24 @end
23 25
24 -@implementation CNLiveLoginRequestModel 26 +@implementation CNLiveLoginRequest
  27 +static const NSInteger timeValue = 1.5;
  28 +
25 #pragma mark - 单例 29 #pragma mark - 单例
26 + (instancetype)manager { 30 + (instancetype)manager {
27 - static CNLiveLoginRequestModel *_singleton = nil; 31 + static CNLiveLoginRequest *_singleton = nil;
28 static dispatch_once_t onceToken; 32 static dispatch_once_t onceToken;
29 dispatch_once(&onceToken, ^{ 33 dispatch_once(&onceToken, ^{
30 - //不能再使用alloc方法  
31 - //因为已经重写了allocWithZone方法,所以这里要调用父类的分配空间的方法  
32 _singleton = [[super allocWithZone:NULL] init]; 34 _singleton = [[super allocWithZone:NULL] init];
33 BOOL isAutoLogin = [IMAPlatform isAutoLogin]; 35 BOOL isAutoLogin = [IMAPlatform isAutoLogin];
  36 +
  37 + if (isAutoLogin) {
  38 + _singleton.loginParam = [IMALoginParam loadFromLocal];
34 39
35 - if (isAutoLogin) {  
36 - _singleton.loginParam = [IMALoginParam loadFromLocal];  
37 -  
38 - } else {  
39 - _singleton.loginParam = [[IMALoginParam alloc] init];  
40 -  
41 - } 40 + } else {
  41 + _singleton.loginParam = [[IMALoginParam alloc] init];
  42 +
  43 + }
42 [IMAPlatform configWith:_singleton.loginParam.config]; 44 [IMAPlatform configWith:_singleton.loginParam.config];
43 45
44 }); 46 });
@@ -48,24 +50,21 @@ @@ -48,24 +50,21 @@
48 50
49 // 防止外部调用alloc 或者 new 51 // 防止外部调用alloc 或者 new
50 + (instancetype)allocWithZone:(struct _NSZone *)zone { 52 + (instancetype)allocWithZone:(struct _NSZone *)zone {
51 - return [CNLiveLoginRequestModel manager];  
52 - 53 + return [CNLiveLoginRequest manager];
53 } 54 }
54 55
55 // 防止外部调用copy 56 // 防止外部调用copy
56 - (id)copyWithZone:(nullable NSZone *)zone { 57 - (id)copyWithZone:(nullable NSZone *)zone {
57 - return [CNLiveLoginRequestModel manager];  
58 - 58 + return [CNLiveLoginRequest manager];
59 } 59 }
60 60
61 // 防止外部调用mutableCopy 61 // 防止外部调用mutableCopy
62 - (id)mutableCopyWithZone:(nullable NSZone *)zone { 62 - (id)mutableCopyWithZone:(nullable NSZone *)zone {
63 - return [CNLiveLoginRequestModel manager];  
64 - 63 + return [CNLiveLoginRequest manager];
65 } 64 }
66 65
67 //获取token 66 //获取token
68 -- (void)getTIMLoginToken:(NSString *)identifier success:(void (^)(NSString *))success failed:(void (^)(int, NSString *))failed{ 67 +- (void)getTIMLoginToken:(NSString *)identifier success:(void (^)(NSString * token))success failed:(void (^)(int code, NSString * msg))failed{
69 NSDictionary *params = @{@"appId":AppId, 68 NSDictionary *params = @{@"appId":AppId,
70 @"plat":@"i", 69 @"plat":@"i",
71 @"sdkAppId":SdkAppId, 70 @"sdkAppId":SdkAppId,
@@ -75,7 +74,7 @@ @@ -75,7 +74,7 @@
75 [CNLiveNetworking setAllowRequestDefaultArgument:YES]; 74 [CNLiveNetworking setAllowRequestDefaultArgument:YES];
76 [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:TIM_GetTokenUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) { 75 [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:TIM_GetTokenUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
77 if (!error) { 76 if (!error) {
78 - if (responseObject && ![responseObject isKindOfClass:[NSNull class]] && [responseObject isKindOfClass:[NSDictionary class]] && [[responseObject allKeys] containsObject:@"data"] && [[responseObject objectForKey:@"data"] isKindOfClass:[NSDictionary class]]) { 77 + if (responseObject && [responseObject isKindOfClass:[NSDictionary class]] && [[responseObject allKeys] containsObject:@"data"] && [[responseObject objectForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
79 NSNumber *code = responseObject[@"errorCode"]; 78 NSNumber *code = responseObject[@"errorCode"];
80 if (code && code.intValue == 0) { 79 if (code && code.intValue == 0) {
81 if (success) { 80 if (success) {
@@ -90,72 +89,118 @@ @@ -90,72 +89,118 @@
90 } 89 }
91 90
92 }else{ 91 }else{
93 - if (failed) failed(31012,@"Token acquisition failure"); 92 + if (failed) failed(31012, @"获取token失败");
94 } 93 }
95 }]; 94 }];
96 95
97 } 96 }
98 97
99 -- (void)loginTIM:(NSString *)uid success:(TIMLoginSucc)success failed:(TIMFail)failed{  
100 - 98 +- (void)loginTIM:(NSString *)uid success:(void (^)(void))success failed:(void (^)(int code, NSString * msg))failed{
  99 + [QMUITips showLoading:@"正在连接服务器..." inView:[UIApplication sharedApplication].keyWindow];
  100 +
  101 + // 1.获取token
101 [self getTIMLoginToken:uid success:^(NSString * _Nonnull token) { 102 [self getTIMLoginToken:uid success:^(NSString * _Nonnull token) {
102 - self.loginParam.identifier = CNUserShareModel.uid; 103 +
  104 + self.loginParam.identifier = uid;
103 self.loginParam.userSig = token; 105 self.loginParam.userSig = token;
104 self.loginParam.tokenTime = [[NSDate date] timeIntervalSince1970]; 106 self.loginParam.tokenTime = [[NSDate date] timeIntervalSince1970];
105 107
  108 + // 2.登录im
106 [[IMAPlatform sharedInstance] login:self.loginParam succ:^{ 109 [[IMAPlatform sharedInstance] login:self.loginParam succ:^{
107 -  
108 -// [NBSAppAgent setUserIdentifier:[CNLiveBusinessTools getSidIdfv]];  
109 [QMUITips hideAllToastInView:[UIApplication sharedApplication].keyWindow animated:YES]; 110 [QMUITips hideAllToastInView:[UIApplication sharedApplication].keyWindow animated:YES];
110 - [QMUITips showSucceed:@"登录成功" inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:1.5]; 111 +
111 [self.loginParam saveToLocal]; 112 [self.loginParam saveToLocal];
112 -// [[AppDelegate sharedAppDelegate] registNotification];  
113 - [[IMAPlatform sharedInstance] configHost:self.loginParam];  
114 - [IMAPlatform sharedInstance].didConnectSuccess = YES;  
115 - //电商  
116 - NSString *userID = CNUserShareModel.uid;  
117 -// [[DSCnliveShopSDKManager sharedManager] loginUser:userID];  
118 - //设置APP已活跃  
119 - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"is_Active_Application"];  
120 - [[NSUserDefaults standardUserDefaults] synchronize];  
121 113
122 [[IMAPlatform sharedInstance].contactMgr asyncUpdateContact]; 114 [[IMAPlatform sharedInstance].contactMgr asyncUpdateContact];
123 [[IMAPlatform sharedInstance].contactMgr saveGroupIdList:YES]; 115 [[IMAPlatform sharedInstance].contactMgr saveGroupIdList:YES];
124 [[IMAPlatform sharedInstance] configHost:self.loginParam]; 116 [[IMAPlatform sharedInstance] configHost:self.loginParam];
125 [IMAPlatform sharedInstance].didConnectSuccess = YES; 117 [IMAPlatform sharedInstance].didConnectSuccess = YES;
126 - //电商  
127 -// NSString *userID = CNUserShareModel.uid;  
128 -// [[DSCnliveShopSDKManager sharedManager] loginUser:userID]; 118 +
  119 + // 听云
  120 + [NBSAppAgent setUserIdentifier:[CNLiveBusinessTools getSidIdfv]];
  121 +
  122 + // 设置电商sdk
  123 +// [[DSCnliveShopSDKManager sharedManager] loginUser:uid];
  124 +
129 //设置APP已活跃 125 //设置APP已活跃
130 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"is_Active_Application"]; 126 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"is_Active_Application"];
131 [[NSUserDefaults standardUserDefaults] synchronize]; 127 [[NSUserDefaults standardUserDefaults] synchronize];
132 128
  129 + [QMUITips showSucceed:@"登录成功" inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
  130 + success?success():@"";
  131 +
  132 + // 3.im配置信息
133 [[IMAPlatform sharedInstance].host asyncSetAllowType:TIM_FRIEND_NEED_CONFIRM succ:^{ 133 [[IMAPlatform sharedInstance].host asyncSetAllowType:TIM_FRIEND_NEED_CONFIRM succ:^{
134 NSLog(@"asyncSetAllowType Suc"); 134 NSLog(@"asyncSetAllowType Suc");
135 [self.loginParam saveToLocal]; 135 [self.loginParam saveToLocal];
136 136
137 } fail:^(int code, NSString *msg) { 137 } fail:^(int code, NSString *msg) {
138 NSLog(@"asyncSetAllowType failed : %@", msg); 138 NSLog(@"asyncSetAllowType failed : %@", msg);
  139 +
139 }]; 140 }];
140 - success?success():@"";  
141 141
142 } fail:^(int code, NSString *msg) { 142 } fail:^(int code, NSString *msg) {
143 NSLog(@"login failed : %@", msg); 143 NSLog(@"login failed : %@", msg);
144 - failed?failed(code, msg):@"";  
145 - 144 + [QMUITips hideAllToastInView:[UIApplication sharedApplication].keyWindow animated:YES];
146 if (code == 6208) { 145 if (code == 6208) {
147 //离线被踢下线重新登录 146 //离线被踢下线重新登录
148 -// [weakSelf resumeLogin]; 147 + [self resumeLogin];
  148 + }
  149 + else{
  150 + [QMUITips showError:msg inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
  151 + failed?failed(code, msg):@"";
149 } 152 }
150 - else  
151 - [QMUITips showError:msg inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:1.5];  
152 - [QMUITips hideAllToastInView:[UIApplication sharedApplication].keyWindow animated:YES];  
153 }]; 153 }];
  154 +
154 } failed:^(int code, NSString * _Nonnull msg) { 155 } failed:^(int code, NSString * _Nonnull msg) {
155 NSLog(@"token code:%d msg:%@", code, msg); 156 NSLog(@"token code:%d msg:%@", code, msg);
156 [QMUITips hideAllToastInView:[UIApplication sharedApplication].keyWindow animated:YES]; 157 [QMUITips hideAllToastInView:[UIApplication sharedApplication].keyWindow animated:YES];
  158 + [QMUITips showError:msg inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
157 failed?failed(code, msg):@""; 159 failed?failed(code, msg):@"";
  160 +
158 }]; 161 }];
159 162
160 } 163 }
  164 +
  165 +// 如果遇到离线被踢下线重新登录
  166 +- (void)resumeLogin {
  167 + __weak typeof(self)weakSelf = self;
  168 + [[IMAPlatform sharedInstance] login:self.loginParam succ:^{
  169 + [QMUITips hideAllToastInView:[UIApplication sharedApplication].keyWindow animated:YES];
  170 + [QMUITips showSucceed:@"登录成功" inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
  171 + [self.loginParam saveToLocal];
  172 +
  173 + [[IMAPlatform sharedInstance] configHost:self.loginParam];
  174 + [IMAPlatform sharedInstance].didConnectSuccess = YES;
  175 +
  176 + [[IMAPlatform sharedInstance].host asyncSetAllowType:TIM_FRIEND_NEED_CONFIRM succ:^{
  177 + NSLog(@"asyncSetAllowType Suc");
  178 + [self.loginParam saveToLocal];
  179 +
  180 + } fail:^(int code, NSString *msg) {
  181 + NSLog(@"asyncSetAllowType failed : %@", msg);
  182 + }];
  183 +
  184 + } fail:^(int code, NSString *msg) {
  185 + NSLog(@"tokenCode login failed : %@", msg);
  186 + if (code == 6028) {
  187 + dispatch_async(dispatch_get_main_queue(), ^{
  188 + QMUIAlertAction *action = [QMUIAlertAction actionWithTitle:@"重试" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
  189 + [weakSelf resumeLogin];
  190 + }];
  191 + QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"连接服务器失败,请点击重试" message:@"" preferredStyle:QMUIAlertControllerStyleActionSheet];
  192 + [alertController addAction:action];
  193 +
  194 + NSMutableDictionary *titleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
  195 +
  196 + titleAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
  197 +
  198 + action.buttonAttributes = titleAttributs;
  199 + [alertController showWithAnimated:YES];
  200 +
  201 + });
  202 + }
  203 + }];
  204 +}
  205 +
161 @end 206 @end
CNLiveLoginModule/Classes/View/CNLiveCompleteInfoView.m
@@ -23,11 +23,9 @@ @@ -23,11 +23,9 @@
23 23
24 #import "TIMAdapter.h" 24 #import "TIMAdapter.h"
25 #import "CommonLibrary.h" 25 #import "CommonLibrary.h"
26 -#import "NBSAppAgent.h"  
27 -#import "CNLiveBusinessTools.h"  
28 #import "CNLiveCategory.h" 26 #import "CNLiveCategory.h"
29 27
30 -#import "CNLiveLoginRequestModel.h" 28 +#import "CNLiveLoginRequest.h"
31 29
32 @interface CNLiveCompleteInfoView()<UITextFieldDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,TZImagePickerControllerDelegate,QMUIAlertControllerDelegate>{ 30 @interface CNLiveCompleteInfoView()<UITextFieldDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,TZImagePickerControllerDelegate,QMUIAlertControllerDelegate>{
33 UIImage *_image; 31 UIImage *_image;
@@ -173,8 +171,6 @@ static const NSInteger timeValue = 1.5; @@ -173,8 +171,6 @@ static const NSInteger timeValue = 1.5;
173 if(!strongSelf) return ; 171 if(!strongSelf) return ;
174 strongSelf->_image = image; 172 strongSelf->_image = image;
175 [strongSelf modifyIcon]; 173 [strongSelf modifyIcon];
176 -// [strongSelf.head setImage:image forState:UIControlStateNormal];  
177 -  
178 dispatch_async(dispatch_get_main_queue(), ^{ 174 dispatch_async(dispatch_get_main_queue(), ^{
179 [weakCameraController dismissViewControllerAnimated:YES completion:nil]; 175 [weakCameraController dismissViewControllerAnimated:YES completion:nil];
180 }); 176 });
@@ -201,7 +197,6 @@ static const NSInteger timeValue = 1.5; @@ -201,7 +197,6 @@ static const NSInteger timeValue = 1.5;
201 if(!strongSelf) return ; 197 if(!strongSelf) return ;
202 strongSelf->_image = [photos firstObject]; 198 strongSelf->_image = [photos firstObject];
203 [strongSelf modifyIcon]; 199 [strongSelf modifyIcon];
204 -// [strongSelf.head setImage:[photos firstObject] forState:UIControlStateNormal];  
205 }]; 200 }];
206 [(UIViewController *)strongSelf.delegate presentViewController:picker animated:YES completion:nil]; 201 [(UIViewController *)strongSelf.delegate presentViewController:picker animated:YES completion:nil];
207 }]; 202 }];
@@ -287,8 +282,7 @@ static const NSInteger timeValue = 1.5; @@ -287,8 +282,7 @@ static const NSInteger timeValue = 1.5;
287 [strongSelf.delegate loginSuccess:strongSelf result:result]; 282 [strongSelf.delegate loginSuccess:strongSelf result:result];
288 } 283 }
289 284
290 - [QMUITips showLoading:@"正在连接服务器..." inView:strongSelf.superview];  
291 - [strongSelf syncIM]; 285 + [strongSelf connectionIM];
292 286
293 } failure:^(NSDictionary *errorDic) { 287 } failure:^(NSDictionary *errorDic) {
294 __strong typeof(weakSelf) strongSelf = weakSelf; 288 __strong typeof(weakSelf) strongSelf = weakSelf;
@@ -301,41 +295,13 @@ static const NSInteger timeValue = 1.5; @@ -301,41 +295,13 @@ static const NSInteger timeValue = 1.5;
301 } 295 }
302 296
303 // 连接IM 297 // 连接IM
304 -- (void)syncIM {  
305 - [CNLiveLoginRequestModel getTIMLoginToken:CNUserShareModel.uid successBlock:^(NSString *token) {  
306 - self.loginParam.identifier = CNUserShareModel.uid;  
307 - self.loginParam.userSig = token;  
308 - self.loginParam.tokenTime = [[NSDate date] timeIntervalSince1970];  
309 -  
310 - [[IMAPlatform sharedInstance] login:self.loginParam succ:^{  
311 - [QMUITips hideAllToastInView:self.superview animated:YES];  
312 - [NBSAppAgent setUserIdentifier:[CNLiveBusinessTools getSidIdfv]];  
313 - [self.loginParam saveToLocal];  
314 -// [[AppDelegate sharedAppDelegate] registNotification];  
315 - [[IMAPlatform sharedInstance] configHost:self.loginParam];  
316 -  
317 -// [[AppDelegate sharedAppDelegate] enterMainUI];  
318 -  
319 - //游客浏览后登陆  
320 -// [self showTouristsLoginTipsView];  
321 -  
322 - [[IMAPlatform sharedInstance].host asyncSetAllowType:TIM_FRIEND_NEED_CONFIRM succ:^{  
323 - NSLog(@"asyncSetAllowType Suc");  
324 - [self.loginParam saveToLocal];  
325 - } fail:^(int code, NSString *msg) {  
326 - NSLog(@"asyncSetAllowType failed : %@", msg);  
327 - }];  
328 -  
329 - } fail:^(int code, NSString *msg) {  
330 - NSLog(@"login failed : %@", msg);  
331 - [QMUITips hideAllToastInView:self.superview animated:YES];  
332 - [QMUITips showError:msg inView:self.superview hideAfterDelay:timeValue];  
333 - }]; 298 +- (void)connectionIM {
  299 + [[CNLiveLoginRequest manager] loginTIM:CNUserShareModel.uid success:^{
  300 + // 进入tabbar
  301 +
  302 + } failed:^(int code, NSString * _Nonnull msg) {
  303 + // 错误逻辑
334 304
335 - } failedBlock:^(int code, NSString *errorMsg) {  
336 - NSLog(@"token code:%d error:%@", code, errorMsg);  
337 - [QMUITips hideAllToastInView:self.superview animated:YES];  
338 - [QMUITips showError:errorMsg inView:self.superview hideAfterDelay:timeValue];  
339 }]; 305 }];
340 306
341 } 307 }
CNLiveLoginModule/Classes/View/CNLiveLoginView.m
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 #import "TIMAdapter.h" 19 #import "TIMAdapter.h"
20 #import "CommonLibrary.h" 20 #import "CommonLibrary.h"
21 21
22 -#import "CNLiveLoginRequestModel.h" 22 +#import "CNLiveLoginRequest.h"
23 23
24 #import "CNLiveLoginCountryView.h" 24 #import "CNLiveLoginCountryView.h"
25 #import "CNLiveLoginTextField.h" 25 #import "CNLiveLoginTextField.h"
@@ -247,22 +247,24 @@ static const NSInteger timeValue = 1.5; @@ -247,22 +247,24 @@ static const NSInteger timeValue = 1.5;
247 #pragma mark - CNLiveCountDownButton Delegate 247 #pragma mark - CNLiveCountDownButton Delegate
248 // 倒计时按钮点击 248 // 倒计时按钮点击
249 - (void)countDownButtonDidClick:(CNLiveCountDownButton *)button { 249 - (void)countDownButtonDidClick:(CNLiveCountDownButton *)button {
  250 + [_account resignFirstResponder];
  251 + [_code resignFirstResponder];
250 //获取验证码 252 //获取验证码
251 if ([_account.text isEqualToString:@""]) { 253 if ([_account.text isEqualToString:@""]) {
252 - [QMUITips showError:@"请输入手机号" inView:self.superview hideAfterDelay:timeValue]; 254 + [QMUITips showError:@"请输入手机号" inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
253 return; 255 return;
254 } 256 }
255 // 按钮点击后将enabled设置为NO 257 // 按钮点击后将enabled设置为NO
256 button.userInteractionEnabled = NO; 258 button.userInteractionEnabled = NO;
257 259
258 __weak typeof(self) weakSelf = self; 260 __weak typeof(self) weakSelf = self;
259 - [QMUITips showLoadingInView:self.superview]; 261 + [QMUITips showLoadingInView:[UIApplication sharedApplication].keyWindow];
260 [CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeShortcutLogin mobile:_account.text countryCode:_countryCode success:^(id result) { 262 [CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeShortcutLogin mobile:_account.text countryCode:_countryCode success:^(id result) {
261 button.userInteractionEnabled = YES; 263 button.userInteractionEnabled = YES;
262 __strong typeof(weakSelf) strongSelf = weakSelf; 264 __strong typeof(weakSelf) strongSelf = weakSelf;
263 if(!strongSelf) return; 265 if(!strongSelf) return;
264 - [QMUITips hideAllToastInView:strongSelf.superview animated:YES];  
265 - [QMUITips showSucceed:@"验证码已发送" inView:strongSelf.superview hideAfterDelay:timeValue]; 266 + [QMUITips hideAllToastInView:[UIApplication sharedApplication].keyWindow animated:YES];
  267 + [QMUITips showSucceed:@"验证码已发送" inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
266 button.backgroundColor = [UIColor colorWithRed:222/255.0 green:222/255.0 blue:222/255.0 alpha:1.0]; 268 button.backgroundColor = [UIColor colorWithRed:222/255.0 green:222/255.0 blue:222/255.0 alpha:1.0];
267 button.frame = CGRectMake(self.frame.size.width-110, self.account.bottom+space+10, 110, rowHeight-10); 269 button.frame = CGRectMake(self.frame.size.width-110, self.account.bottom+space+10, 110, rowHeight-10);
268 [button setImage:nil forState:UIControlStateNormal]; 270 [button setImage:nil forState:UIControlStateNormal];
@@ -273,11 +275,11 @@ static const NSInteger timeValue = 1.5; @@ -273,11 +275,11 @@ static const NSInteger timeValue = 1.5;
273 button.userInteractionEnabled = YES; 275 button.userInteractionEnabled = YES;
274 __strong typeof(weakSelf) strongSelf = weakSelf; 276 __strong typeof(weakSelf) strongSelf = weakSelf;
275 if(!strongSelf) return; 277 if(!strongSelf) return;
276 - [QMUITips hideAllToastInView:strongSelf.superview animated:YES]; 278 + [QMUITips hideAllToastInView:[UIApplication sharedApplication].keyWindow animated:YES];
277 if ([errorDic[@"errorCode"] integerValue] == 408) { 279 if ([errorDic[@"errorCode"] integerValue] == 408) {
278 - [QMUITips showError:@"请输入正确的手机号" inView:strongSelf.superview hideAfterDelay:timeValue]; 280 + [QMUITips showError:@"请输入正确的手机号" inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
279 }else{ 281 }else{
280 - [QMUITips showError:[errorDic objectForKey:@"errorMessage"] inView:strongSelf.superview hideAfterDelay:timeValue]; 282 + [QMUITips showError:[errorDic objectForKey:@"errorMessage"] inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
281 } 283 }
282 284
283 }]; 285 }];
@@ -306,20 +308,22 @@ static const NSInteger timeValue = 1.5; @@ -306,20 +308,22 @@ static const NSInteger timeValue = 1.5;
306 308
307 #pragma mark - Action 309 #pragma mark - Action
308 - (void)loginDidClicked:(UIButton *)btn{ 310 - (void)loginDidClicked:(UIButton *)btn{
  311 + [_account resignFirstResponder];
  312 + [_code resignFirstResponder];
309 //登录 313 //登录
310 if ([_account.text isEqualToString:@""]) { 314 if ([_account.text isEqualToString:@""]) {
311 - [QMUITips showError:@"请输入手机号" inView:self.superview hideAfterDelay:timeValue]; 315 + [QMUITips showError:@"请输入手机号" inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
312 return; 316 return;
313 } 317 }
314 if ([_code.text isEqualToString:@""]) { 318 if ([_code.text isEqualToString:@""]) {
315 - [QMUITips showError:@"请输入验证码" inView:self.superview hideAfterDelay:timeValue]; 319 + [QMUITips showError:@"请输入验证码" inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
316 return; 320 return;
317 } 321 }
318 btn.userInteractionEnabled = NO; 322 btn.userInteractionEnabled = NO;
319 // 隐藏键盘 323 // 隐藏键盘
320 [self.superview endEditing:YES]; 324 [self.superview endEditing:YES];
321 325
322 - [QMUITips showLoading:@"登录中" inView:self.superview]; 326 + [QMUITips showLoading:@"登录中" inView:[UIApplication sharedApplication].keyWindow];
323 327
324 __weak typeof(self) weakSelf = self; 328 __weak typeof(self) weakSelf = self;
325 [CNLiveUserSystemCenter shortcutLoginWithUserName:_account.text countryCode:_countryCode verificationCode:_code.text frmId:@"apple" success:^(id result) { 329 [CNLiveUserSystemCenter shortcutLoginWithUserName:_account.text countryCode:_countryCode verificationCode:_code.text frmId:@"apple" success:^(id result) {
@@ -333,8 +337,8 @@ static const NSInteger timeValue = 1.5; @@ -333,8 +337,8 @@ static const NSInteger timeValue = 1.5;
333 btn.userInteractionEnabled = YES; 337 btn.userInteractionEnabled = YES;
334 __strong typeof(weakSelf) strongSelf = weakSelf; 338 __strong typeof(weakSelf) strongSelf = weakSelf;
335 if(!strongSelf) return; 339 if(!strongSelf) return;
336 - [QMUITips hideAllToastInView:strongSelf.superview animated:YES];  
337 - [QMUITips showError:[errorDic objectForKey:@"errorMessage"] inView:strongSelf.superview hideAfterDelay:timeValue]; 340 + [QMUITips hideAllToastInView:[UIApplication sharedApplication].keyWindow animated:YES];
  341 + [QMUITips showError:[errorDic objectForKey:@"errorMessage"] inView:[UIApplication sharedApplication].keyWindow hideAfterDelay:timeValue];
338 }]; 342 }];
339 } 343 }
340 344
@@ -348,94 +352,11 @@ static const NSInteger timeValue = 1.5; @@ -348,94 +352,11 @@ static const NSInteger timeValue = 1.5;
348 } 352 }
349 [CNUserInfoManager saveUserinfoDic:dic]; 353 [CNUserInfoManager saveUserinfoDic:dic];
350 354
351 -// // YES 新用户 NO 老用户  
352 -// BOOL isNewUser = [dic[@"isNewUser"] intValue] != 0;  
353 -// if (self.delegate && [self.delegate respondsToSelector:@selector(loginSuccess:isNewUser:result:)]) {  
354 -// [self.delegate loginSuccess:self isNewUser:isNewUser result:result];  
355 -// }  
356 -  
357 - [CNLiveLoginRequestModel getTIMLoginToken:CNUserShareModel.uid successBlock:^(NSString *token) {  
358 -  
359 - _loginParam.identifier = CNUserShareModel.uid;  
360 - _loginParam.userSig = token;  
361 - _loginParam.tokenTime = [[NSDate date] timeIntervalSince1970];  
362 -  
363 - [[IMAPlatform sharedInstance] login:_loginParam succ:^{  
364 -  
365 -// [NBSAppAgent setUserIdentifier:[CNLiveBusinessTools getSidIdfv]];  
366 - [QMUITips hideAllToastInView:self.superview animated:YES];  
367 - [QMUITips showSucceed:@"登录成功" inView:self.superview hideAfterDelay:1.5];  
368 - [_loginParam saveToLocal];  
369 -// [[AppDelegate sharedAppDelegate] registNotification];  
370 - [[IMAPlatform sharedInstance] configHost:_loginParam];  
371 - [IMAPlatform sharedInstance].didConnectSuccess = YES;  
372 - //电商  
373 - NSString *userID = CNUserShareModel.uid;  
374 -// [[DSCnliveShopSDKManager sharedManager] loginUser:userID];  
375 - //设置APP已活跃  
376 - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"is_Active_Application"];  
377 - [[NSUserDefaults standardUserDefaults] synchronize];  
378 -  
379 -  
380 -  
381 - if ([result[@"data"][@"isNewUser"] intValue] == 0) {  
382 - //老用户  
383 -// [[AppDelegate sharedAppDelegate] enterMainUI];  
384 -// [[AppDelegate sharedAppDelegate] registNotification];  
385 - [[IMAPlatform sharedInstance].contactMgr asyncUpdateContact];  
386 - [[IMAPlatform sharedInstance].contactMgr saveGroupIdList:YES];  
387 - [[IMAPlatform sharedInstance] configHost:_loginParam];  
388 - [IMAPlatform sharedInstance].didConnectSuccess = YES;  
389 - //电商  
390 - NSString *userID = CNUserShareModel.uid;  
391 -// [[DSCnliveShopSDKManager sharedManager] loginUser:userID];  
392 - //设置APP已活跃  
393 - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"is_Active_Application"];  
394 - [[NSUserDefaults standardUserDefaults] synchronize];  
395 -  
396 - }  
397 - else {  
398 - //新用户  
399 -// [OpenInstallSDK reportRegister];  
400 -// CNLoginIUsernfoViewController *vc = [[CNLoginIUsernfoViewController alloc] init];  
401 -// NSString *tel = _accountTextF.text;  
402 -// if(_accountTextF.text.length == 11){  
403 -// tel = [_accountTextF.text stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"XXXX"];  
404 -// }  
405 -// NSLog(@"tel:%@",tel);  
406 -// vc.mobileStr = tel;  
407 -// [self presentViewController:vc animated:NO completion:NULL];  
408 - }  
409 -// [[NSNotificationCenter defaultCenter] postNotificationName:kCNLive_LoginSuccess object:nil];  
410 -  
411 -// [CNDSShopActionViewModel networkParamAction];  
412 -  
413 - [[IMAPlatform sharedInstance].host asyncSetAllowType:TIM_FRIEND_NEED_CONFIRM succ:^{  
414 - NSLog(@"asyncSetAllowType Suc");  
415 - [_loginParam saveToLocal];  
416 -  
417 - } fail:^(int code, NSString *msg) {  
418 - NSLog(@"asyncSetAllowType failed : %@", msg);  
419 - }];  
420 - // [self dismissViewControllerAnimated:YES completion:nil];  
421 -  
422 - } fail:^(int code, NSString *msg) {  
423 - NSLog(@"login failed : %@", msg);  
424 - if (code == 6208) {  
425 - //离线被踢下线重新登录  
426 -// [weakSelf resumeLogin];  
427 - }  
428 - else  
429 - [QMUITips showError:msg inView:self.superview hideAfterDelay:1.5];  
430 - [QMUITips hideAllToastInView:self.superview animated:YES];  
431 - }];  
432 -  
433 - } failedBlock:^(int code, NSString *errorMsg) {  
434 - NSLog(@"token code:%d error:%@", code, errorMsg);  
435 - [QMUITips hideAllToastInView:self.superview animated:YES];  
436 -  
437 - }];  
438 - 355 + // YES 新用户 NO 老用户
  356 + BOOL isNewUser = [dic[@"isNewUser"] intValue] != 0;
  357 + if (self.delegate && [self.delegate respondsToSelector:@selector(loginSuccess:isNewUser:result:)]) {
  358 + [self.delegate loginSuccess:self isNewUser:isNewUser result:result];
  359 + }
439 } 360 }
440 361
441 @end 362 @end