更新時間:2019-11-20
用戶可以更改自己的頭像,使用的頭像可以是系統(tǒng)頭像也可以是自定義頭像。同時用戶可以獲取頭像,在獲取頭像時服務器會推送獲取頭像的回調消息給用戶,從服務器上得到指定聯(lián)系人的頭像信息。
已完成組件的初始化和登錄。
設置系統(tǒng)頭像
代碼示例:
- (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時間戳,作為聯(lián)系人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]; } }
獲取聯(lián)系人頭像
傳入的參數(shù)TSDK_S_GET_ICON_PARAM即為獲取頭像請求參數(shù),需要填寫查詢的帳戶以及序列號。
- (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); }
查詢頭像的結果信息包括操作結果,查詢序號,系統(tǒng)頭像id(用戶設置的是系統(tǒng)頭像)或者自定義頭像文件路徑(用戶設置的是自定義頭像)。
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;
無。