本文将教你如何在iOS端快速即成即时通讯:步骤如下
1 集成leancloud即时通讯开发环境
2.使用官方demo所使用的UI框架,实现即时通讯
1使用leancloud所使用的IM框架
只需在podfile文件中添加
pod 'AVOSCloudIM'
2使用官方demo所使用的UI框架
以下都是参照https://github.com/leancloud/leanchat-ios
- 加入 LeanChatLib 的 pod 依赖,或拖动 LeanChatLib 的代码文件进项目,改 UI 和调整功能方便些
在podfile文件中添加
pod 'LeanChatLib'
- 依次在合适的地方加入以下代码:
应用启动后,初始化,以及配置 IM
[AVOSCloud setApplicationId:@"YourAppId" clientKey:@"YourAppKey"];
[CDChatManager manager].userDelegate = [[CDUserFactory alloc] init];
配置一个 UserFactory,遵守 CDUserDelegate协议即可。
#import "CDUserFactory.h"
#import <LeanChatLib/LeanChatLib.h>
@interface CDUserFactory ()<CDUserDelegate>
@end
@implementation CDUserFactory
#pragma mark - CDUserDelegate
- (void)cacheUserByIds:(NSSet *)userIds block:(AVIMArrayResultBlock)block{
block(nil,nil); // don't forget it
}
//这里的username avatarurl可以根据你项目的需求去改变
- (id<CDUserModelDelegate>)getUserById:(NSString *)userId {
CDUser *user = [[CDUser alloc] init];
user.userId = userId;
user