更新时间:2019-11-20
用户可以更改自己的头像,使用的头像可以是系统头像也可以是自定义头像。同时用户可以获取头像,在获取头像时服务器会推送获取头像的回调消息给用户,从服务器上得到指定联系人的头像信息。
已完成组件的初始化和登录。
设置系统头像
代码示例:
- (void)setSystemHead:(int)sysIconID withCmpletion:(void(^)(BOOL result))completionBlock { TSDK_RESULT set_sys_result = tsdk_set_system_icon((TSDK_UINT32)sysIconID); BOOL result = set_sys_result == TSDK_SUCCESS; if (completionBlock) { completionBlock(result); } if (result) { [self setHeadID:[NSString stringWithFormat:@"%d", sysIconID]]; } }
设置自定义头像
代码示例:
- (void)setHeadImage:(UIImage *)image completion:(void(^)(BOOL result, NSString *headID))completionBlock { //自定义头像接口需要上传三种尺寸的图片:52x52 120x120 320x320 NSData *minImg = [self imgWithSize:SIZE52 image:image]; NSData *midImg = [self imgWithSize:SIZE120 image:image]; NSData *maxImg = [self imgWithSize:SIZE320 image:image]; NSString *path = NSTemporaryDirectory(); NSString *iconPathMinImg = [path stringByAppendingPathComponent:@"minImg"]; NSString *iconPathMidImg = [path stringByAppendingPathComponent:@"midImg"]; NSString *iconPathMaxImg = [path stringByAppendingPathComponent:@"maxImg"]; [minImg writeToFile:iconPathMinImg atomically:YES]; [midImg writeToFile:iconPathMidImg atomically:YES]; [maxImg writeToFile:iconPathMaxImg atomically:YES]; TSDK_S_ICON_INFO* icon_info = (TSDK_S_ICON_INFO*)malloc(sizeof(TSDK_S_ICON_INFO)); memset(icon_info, 0, sizeof(TSDK_S_ICON_INFO)); strcpy(icon_info->small_icon_path, [iconPathMinImg UTF8String]); strcpy(icon_info->medium_icon_path, [iconPathMidImg UTF8String]); strcpy(icon_info->large_icon_path, [iconPathMaxImg UTF8String]); TSDK_CHAR *modifyTime = (TSDK_CHAR *)malloc(16); memset_s(modifyTime, 16, 0, 16); TSDK_UINT32 length = 16; TSDK_RESULT ret_set_def = tsdk_set_user_def_icon(icon_info, modifyTime, &length); free(icon_info); // 出参modifyTime时间戳,作为联系人headId NSString *mTime = [NSString stringWithUTF8String:modifyTime]; DDLogInfo(@"set image ret: %d modify time: %@", length, mTime); BOOL result = ret_set_def == TSDK_SUCCESS; if (completionBlock) { completionBlock(result, mTime); } if (result) { [self setHeadID:mTime]; } }
获取联系人头像
传入的参数TSDK_S_GET_ICON_PARAM即为获取头像请求参数,需要填写查询的帐户以及序列号。
- (void)loadPersonHeadIconWithAccount:(NSString *)account { TSDK_S_GET_ICON_PARAM *iconParam = (TSDK_S_GET_ICON_PARAM *)malloc(sizeof(TSDK_S_GET_ICON_PARAM)); memset(iconParam, 0, sizeof(TSDK_S_GET_ICON_PARAM)); if (account.length > 0 && account != nil) { strcpy(iconParam->account, [account UTF8String]); } iconParam->seq_no = rand(); TSDK_RESULT result = tsdk_get_user_icon(iconParam); DDLogInfo(@"tsdk_get_user_icon result: %d", result); free(iconParam); }
查询头像的结果信息包括操作结果,查询序号,系统头像id(用户设置的是系统头像)或者自定义头像文件路径(用户设置的是自定义头像)。
case TSDK_E_EADDR_EVT_GET_ICON_RESULT: { DDLogInfo(@"TSDK_E_EADDR_EVT_GET_ICON_RESULT"); BOOL result = notification.param1 == TSDK_SUCCESS; if (!result) { DDLogError(@"TSDK_E_EADDR_EVT_GET_ICON_RESULT,error:%@",[NSString stringWithUTF8String:(TSDK_CHAR *)notification.data]); return; } TSDK_S_GET_ICON_RESULT *getIconResult = (TSDK_S_GET_ICON_RESULT *)notification.data; int sysIconID = getIconResult->icon_id; NSString *acIconFile = [NSString stringWithUTF8String:getIconResult->icon_path]; NSDictionary *resultInfo = @{ TUP_CONTACT_EVENT_RESULT_KEY : [NSNumber numberWithBool:result], TUP_SYS_ICON_ID_KEY : [NSString stringWithFormat:@"%d", sysIconID], TUP_ICON_FILE_KEY : [NSString stringWithFormat:@"%@%@", ICON_PATH, acIconFile] }; [self respondsContactDelegateWithType:CONTACT_E_SEARCH_GET_ICON_RESULT result:resultInfo]; } break;
无。