1 pod 或者手动导入imsdk
2 IM会提供一个SDKAppID 和一个secret长串,工程里只用到SDKAppID 长串给后台配置,并用接口返回给前端验证并登陆
3 appdelegate 中
//初始化ui库(自己写UI可以不调用)
[[TUIKit sharedInstance] setupWithAppId:[kSdkAppId integerValue]]; // SDKAppID 可以在 即时通信 IM 控制台中获取
//接口返回secret长串 之后初始化登陆方法
TIMLoginParam *param = [[TIMLoginParam alloc] init];
//赋值之后调用登陆方法
[[TIMManager sharedInstance] login:param succ:^{
登陆失败会返回错误码 其中6208 代表账号在别的地方登陆,可以实现在线,后台,离线互踢
错误码70001 是超时,需要重新验证,再次调登陆
//登陆成功 用户自己到苹果注册开发者证书,在开发者帐号中下载并生成证书(p12 文件),将生成的 p12 文件传到腾讯证书管理控制台,控制台会自动生成一个证书 ID,将证书 ID 传入一下 busiId 参数中。*/ 上传token (token 从远程通知推送回调里赋值deviceToken) 然后调用传token方法
[[TIMManager sharedInstance] setToken:param succ:^{
4 发消息 (自定义消息,用来加需要字段 IM提供了一个ext字段)
#pragma mark -消息发送
- (void)inputController:(TUIInputController *)inputController didSendMessage:(TUIMessageCellData *)msg{
[_messageController sendMessage:msg];
TUIMessageCellData *data = [TUIMessageCellData new];
data.innerMessage = [TIMMessage new];
data = msg;
TIMIOSOfflinePushConfig *config = [TIMIOSOfflinePushConfig new];
config.ignoreBadge = YES;
config.sound = @"msgTritone.caf";
TIMOfflinePushInfo *info = [TIMOfflinePushInfo new];
//ext:push自定义内容---------------------
NSMutableDictionary *extDic = [NSMutableDictionary new];
//根据当前controller使用者的角色反推用户推送跳转角色
NSString *userId = [[TIMManager sharedInstance] getLoginUser];
if (_bullRoles==BullRole_Gold_Analysts) {
[extDic setObject:@(BullRole_Gold_GeneralUsers) forKey:@"bullRoles"];
//用户端用来展示的title
[extDic setObject:self.title forKey:@"title"];
[extDic setObject:_djfId forKey:@"chatId"];
}else if (_bullRoles==BullRole_Gold_GeneralUsers){
[extDic setObject:@(BullRole_Gold_Analysts) forKey:@"bullRoles"];
[extDic setObject:_djfId forKey:@"chatId"];
[extDic setObject:self.title forKey:@"title"];
}else if (_bullRoles==BullRole_C2C_GeneralUsers){
[extDic setObject:@(BullRole_C2C_Analysts) forKey:@"bullRoles"];
[extDic setObject:userId forKey:@"chatId"];
[extDic setObject:msg.name forKey:@"title"];
}else if (_bullRoles==BullRole_C2C_Analysts){
[extDic setObject:@(BullRole_C2C_GeneralUsers) forKey:@"bullRoles"];
[extDic setObject:userId forKey:@"chatId"];
[extDic setObject:msg.name forKey:@"title"];
}
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:extDic options:NSJSONWritingPrettyPrinted error:nil];
NSString * extStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
info.ext = extStr;
info.pushFlag = TIM_OFFLINE_PUSH_DEFAULT;
// info.desc = @"斗牛IM消息";
info.iosConfig = config;
msg.innerMessage = data.innerMessage;
[msg.innerMessage setOfflinePushInfo:info];
}