融雲集成過程官方文檔:
http://www.rongcloud.cn/docs/ios.html#integration
簡要步驟說明
- 初始化 SDK
#import <RongIMKit/RongIMKit.h>
/** 融雲初始化 */
- (void)setupRongCloud {
[[RCIM sharedRCIM] initWithAppKey:RongCloudKey];
}
- 連接服務器
#import <RongIMKit/RongIMKit.h>
/** 連接服務器 */
- (void)connectToServerWithToken:(NSString *)token {
[[RCIM sharedRCIM] connectWithToken:token success:^(NSString *userId) {
NSLog(@"登錄的用戶是%@", userId);
// 代理提供用戶信息
[RCIM sharedRCIM].userInfoDataSource = self;
// 代理當前用戶信息
RCUserInfo *info = [[RCUserInfo alloc] init];
[RCIM sharedRCIM].currentUserInfo = info;
} error:^(RCConnectErrorCode status) {
NSLog(@"%ld", (long)status);
} tokenIncorrect:^{
NSLog(@"token錯誤");
}];
}
- 提供用戶信息
/** 代理提供用戶信息 */
- (void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *))completion {
RCUserInfo *info = [[RCUserInfo alloc] init];
// 用戶的信息根據userId到APP服務器獲取
...
completion(info);
}
- 會話列表
#import <RongIMKit/RongIMKit.h>
// 創建ViewController繼承RCConversationListViewController
// 參考RCConversationListViewController,根據需求重寫方法
//重寫RCConversationListViewController的onSelectedTableRow事件
- (void)onSelectedTableRow:(RCConversationModelType)conversationModelType
conversationModel:(RCConversationModel *)model
atIndexPath:(NSIndexPath *)indexPath {
// 跳轉會話
RCConversationViewController *conversationVC = [[RCConversationViewController alloc]init];
conversationVC.conversationType = model.conversationType;
conversationVC.targetId = model.targetId;
conversationVC.title = model.conversationTitle;
conversationVC.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:conversationVC animated:YES];
}
- 音視頻的集成參考官方文檔 http://www.rongcloud.cn/docs/ios_callkit.html
遇到的問題,會話列表中的用戶頭像不顯示,進入會話再返回就顯示,或者滑動列表才顯示
解決辦法:目前我是在收到信息和viewDidAppear刷新列表數據
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// 刷新tableView數據
[self.conversationListTableView reloadData];
}
// 接收到信息
- (void)onRCIMReceiveMessage:(RCMessage *)message left:(int)left {
[[RCIMManager shareIntance] updateBadgeValue];
// 刷新tableView數據
[self.conversationListTableView reloadData];
}