Skip to content

Commit f59cb04

Browse files
guangyaoguangyao
authored andcommitted
Fix 离线登录一段时间失败的问题
1 parent 0a9618c commit f59cb04

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

ios/RNNeteaseIm/RNNeteaseIm/NIMViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ typedef void(^SUCCESS) (id param);
1313
typedef void(^ERROR)(NSString *error);
1414
@interface NIMViewController : UIViewController
1515

16+
@property (copy, nonatomic) NSString *strAccount;
17+
@property (copy, nonatomic) NSString *strToken;
18+
1619
+(instancetype)initWithController;
1720
-(instancetype)initWithNIMController;
1821
-(void)deleteCurrentSession:(NSString *)recentContactId andback:(ERROR)error;

ios/RNNeteaseIm/RNNeteaseIm/NIMViewController.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import "ContactViewController.h"
1111

1212
@interface NIMViewController ()<NIMLoginManagerDelegate,NIMConversationManagerDelegate>{
13-
13+
BOOL isLoginFailed;
1414
}
1515

1616
@end
@@ -51,6 +51,7 @@ - (void)onLogin:(NIMLoginStep)step{
5151
break;
5252
case NIMLoginStepLinkOK://连接服务器成功
5353
strStatus = @"5";
54+
[self backLogin];
5455
[self getResouces];
5556
break;
5657
case NIMLoginStepLinkFailed://连接服务器失败
@@ -64,6 +65,7 @@ - (void)onLogin:(NIMLoginStep)step{
6465
break;
6566
case NIMLoginStepLoginFailed://登录失败
6667
strStatus = @"10";
68+
isLoginFailed = YES;
6769
break;
6870
case NIMLoginStepSyncing://开始同步
6971
strStatus = @"13";
@@ -101,6 +103,17 @@ -(void)deleteCurrentSession:(NSString *)recentContactId andback:(ERROR)error{
101103
}
102104
}
103105

106+
//登录失败后重新手动登录
107+
- (void)backLogin{
108+
if (isLoginFailed) {
109+
isLoginFailed = NO;
110+
NSLog(@":%@ :%@",_strAccount,_strToken);
111+
[[NIMSDK sharedSDK].loginManager login:_strAccount token:_strToken completion:^(NSError * _Nullable error) {
112+
NSLog(@"error:%@",error);
113+
}];
114+
}
115+
}
116+
104117
#pragma NIMLoginManagerDelegate
105118
-(void)onKick:(NIMKickReason)code clientType:(NIMLoginClientType)clientType
106119
{

ios/RNNeteaseIm/RNNeteaseIm/RNNeteaseIm.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ - (dispatch_queue_t)methodQueue
9191
NSLog(@"%@:%@",strEorr,error);
9292
}
9393
}];
94+
[NIMViewController initWithController].strToken = token;
95+
[NIMViewController initWithController].strAccount = account;
9496
}
9597

9698
//注销用户

0 commit comments

Comments
 (0)