集成步骤就不说了 文档说的很清楚啦~
1⃣️
集成完毕,我们开始要写代码来做初始化和连接部分啦!
在appdelegate.m文件里 先包含文件
#import <RongIMKit/RongIMKit.h>
[[RCIM sharedRCIM] initWithAppKey:@"y745wfm84ekbv"];
[[RCIM sharedRCIM] connectWithToken:@"/c+PTsQd/mbXxYaLWFmL/Ml1/i98BQyyuh3ScYAwQgny/Z1fXR+A63sHXdPfa7mJFajsnYUO8xsEsR/vqCzApg==" success:^(NSString *userId) {
NSLog(@"登陆成功。当前登录的用户ID:%@", userId);
} error:^(RCConnectErrorCode status) {
NSLog(@"登陆的错误码为:%d",(int)status);
} tokenIncorrect:^{
NSLog(@"token错误");
}];
注:
token的获取我们可以先用融云平台里自己的API调试(在你们自己服务器未完成token部分,可以暂时先用)


返回的token就可以在上述代码中使用了!
2⃣️在ViewController.m里面写代码
先写一个按钮,点击跳转到聊天内容界面:
#import "ViewController.h"
#import <RongIMKit/RongIMKit.h>
@interface ViewController ()
- (IBAction)chat;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)chat
{
RCConversationViewController *chatVc = [[RCConversationViewController alloc] init];
chatVc.title = @"毛毛";
chatVc.conversationType = ConversationType_PRIVATE;
chatVc.targetId = @"123456";
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:chatVc];
[self presentViewController:nav animated:YES completion:nil];
}
@end
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29

3⃣️ 做聊天列表的页面
在appdelegate.m中把根视图转为聊天列表页 而不是viewController
FriendsController *friendsVc = [[FriendsController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:friendsVc];
self.window.rootViewController = nav;
聊天列表的页面 继承RCConversationListViewController类
#import "FriendsController.h"
@interface FriendsController ()
@end
@implementation FriendsController
- (void)viewDidLoad {
[super viewDidLoad];
self.isShowNetworkIndicatorView = YES;
self.showConnectingStatusOnNavigatorBar = YES;
[self setDisplayConversationTypes:@[@(ConversationType_PRIVATE), @(ConversationType_DISCUSSION),@(ConversationType_GROUP),@(ConversationType_SYSTEM),@(ConversationType_APPSERVICE)]];
[self setCollectionConversationType:@[@(ConversationType_GROUP),@(ConversationType_DISCUSSION)]];
self.cellBackgroundColor = [UIColor cyanColor];
self.topCellBackgroundColor = [UIColor yellowColor];
}
#pragma mark - 点击会话列表中中的cell的回调
- (void)onSelectedTableRow:(RCConversationModelType)conversationModelType conversationModel:(RCConversationModel *)model atIndexPath:(NSIndexPath *)indexPath
{
RCConversationViewController *vc = [[RCConversationViewController alloc] init];
vc.conversationType = model.conversationType;
vc.targetId = model.targetId;
vc.title = model.conversationTitle;
[self.navigationController pushViewController:vc animated:YES];
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
问题: 写到这里 我也有一点疑惑 聊天列表会显示跟你聊过天的所有的列表 并且删除了列表的联系人 下次运行的时候还有 是不是只有清空聊天记录缓存才不会显示聊天列表?
============ 有点事 以后更新==================
4⃣️ 获取用户信息 用来显示
在appdelegate.m中写
①遵守协议RCIMUserInfoDataSource