用 TIMSDK 的自定义字段 iOS 示例

以个人用户自定义字段为例

  1. 首先要在 控制台 (功能配置 -> 用户自定义字段) 配置用户自定义字段,然后再调用该接口进行设置,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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容