以个人用户自定义字段为例
- 首先要在 控制台 (功能配置 -> 用户自定义字段) 配置用户自定义字段,然后再调用该接口进行设置,key 值不需要加 Tag_Profile_Custom_ 前缀。
截屏2024-03-22 15.08.06.png
2.调用IM修改用户资料的方法(注意value值为data类型)
NSString *customKey = @"Tag_Profile_Custom_isDesign";
NSString *customValue = @"1";
NSDictionary *dict = @{customKey:[customValue mj_JSONData]};
[info setCustomInfo:dict];
NSLog(@"%@ %@",self.headImgId,self.nickNameTF.text);
[[V2TIMManager sharedInstance] setSelfInfo:info succ:^{
NSLog(@"信息同步成功~~~~~~");
} fail:^(int code, NSString *desc) {
NSLog(@"code == %d desc == %@",code,desc);
}];
3.获取自定义信息(注意:获取的key值是去掉前缀Tag_Profile_Custom_)
[[V2TIMManager sharedInstance] getUsersInfo:@[[NSString stringWithFormat:@"%@",self.userId]] succ:^(NSArray<V2TIMUserFullInfo *> *infoList) {
if (infoList.count == 1) {
V2TIMUserFullInfo *info = infoList.firstObject;
for (NSString *key in info.customInfo) {
NSData value = info.customInfo[key];
NSString stringValue = [[NSString alloc] initWithData:value encoding:NSASCIIStringEncoding];
NSLog(@"keyandvalue = %@,%@", key, stringValue);
}
}
} fail:^(int code, NSString *desc) {
NSLog(@"code == %d desc == %@",code,desc);
}];
打印值:keyandvalue = isDesign,1