本文介绍如何创建一个 IMCloud iOS 项目,实现即时通讯功能。你也可以通过阅读代码,了解即时通讯的最佳实践。
获取 AppID 和 Token,你可以通过阅读密钥说明了解更多 Token 相关信息
Xcode 9.0+
iOS 8.0+ iPhone 或 iPad 真机
项目已配置有效的开发者签名
本步骤为如何创建一个新项目,如集成到已有项目,请直接查看集成 SDK。
打开 Xcode,选择 File > New > Project。
选择 iOS > App,单击 Next。

输入项目名称、团队名称、选择开发语言(Objective-C),单击 Next。
选择项目存储位置,单击 Create。
签名设置:进入 TARGETS > Project Name > Signing & Capabilities,查看 Automatically manage signing 是否勾选,若没有勾选请勾选 ,并在弹出菜单中选择 Enable Automatic。

sudo gem install cocoapods
objectivecpod init
objectivecsource 'https://github.com/volcengine/volcengine-specs.git'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'ByteBusiness' do
# Comment the next line if you don't want to use dynamic frameworks
# use_frameworks!
pod 'im-uikit-tob'
end
objectivecpod repo update
objectivec下载 SDK 和 UIKit 到本地,解压并拷贝文件到项目工程中。其中 UIKit 已经开源,你也可以通过 GitHub 仓库获取 UIKit 源码。
在使用 IMSDK 接口功能前需要先进行初始化操作,在 application 启动函数中添加如下代码。其中 BIMSDKConfig 可配置 IMSDK 的日志监听。
BIMSDKConfig *config = [[BIMSDKConfig alloc] init];
[config setLogListener:^(BIMLogLevel logLevel, NSString * _Nonnull logContent) {
// 日志 输出
}];
[[BIMUIClient sharedInstance] initSDK:[kVEIMDemoAppID integerValue] config:config];
objectivecBIMLogLevel 日志级别含义如下
| 日志级别 | 含义 |
|---|---|
| BIM_LOG_DEBUG | debug 日志, 调试信息。 |
| BIM_LOG_INFO | Info 日志,上下文环境等信息。 |
| BIM_LOG_WARN | warn 日志,警告信息。 |
| BIM_LOG_ERROR | error 日志,错误信息。 |
创建自己的会话列表容器控制器,如 xxxConversationListController,然后将 BIMConversationListController 作为子 vc 添加到 xxxConversationListController,可以在 viewDidLoad 时添加如下代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
BIMConversationListController *conListController = [[BIMConversationListController alloc] init];
conListController.delegate = self;
[self addChildViewController:conListController];
[self.view addSubview:conListController.view];
}
objectivecBIMConversationListController 提供了点击监听,便于业务自定义会话点击事件。
@protocol BIMConversationListControllerDelegate <NSObject>
- (void)conversationListController:(BIMConversationListController *_Nullable)controller didSelectConversation:(BIMConversation *)conversation;
@end
objectivec集成后会话列表页面实现样式参考下图:

创建自己的消息列表容器控制器,如 xxxChatViewController,然后将 BIMChatViewController 作为子 vc 添加到 xxxChatViewController,可以在 viewDidLoad 时添加如下代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
BIMChatViewController *chatVC = [BIMChatViewController chatVCWithConversation:self.conversation];
[self addChildViewController:chatVC];
[self.view addSubview:chatVC.view];
}
objectivec集成后消息列表页面实现样式参考下图:
