智慧服务,成就美好体验 项目咨询

主页 > 服务与支持 > 开发平台 > 客户端SDK参考 > iOS Native SDK > 接口参考 通讯录

入门使用

通讯录

更新时间:2019-11-20

接口名称

接口描述

tsdk_set_system_icon

设置系统头像。

tsdk_set_user_def_icon

设置自定义头像。

tsdk_get_user_icon

搜索联系人头像。

tsdk_search_contacts

搜索联系人。

tsdk_set_system_icon

接口描述

设置系统头像。

注意事项

无。

方法定义

TSDK_API TSDK_RESULT tsdk_set_system_icon(IN TSDK_UINT32 icon_id);
 

参数描述

参数名

是否必须

类型

描述

[in] icon_id

TSDK_UINT32

系统头像序号。

返回值

类型

描述

TSDK_RESULT

成功返回TSDK_SUCCESS,失败返回相应错误码。

代码示例

//OC
- (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]];
    }
}
 

tsdk_set_user_def_icon

接口描述

设置自定义头像。

注意事项

  • 设置自定义头像需注意:自定义头像信息里需要设置头像的内容以及内容的长度,并且头像需要选择为小头像52*52、中头像120*120和大头像320*320三种其中具体大小应根据服务器要求来定。
  • 图片的格式不支持TIFF格式,推荐使用png格式。
  • 图片的大小服务器没有限制,产品可以根据实际的需要进行限制,建议图片大小最大值为2MB。

方法定义

TSDK_API TSDK_RESULT tsdk_set_user_def_icon(IN TSDK_S_ICON_INFO* icon_info,  OUT TSDK_CHAR *update_time, IO TSDK_UINT32 *length);
 

参数描述

参数

是否必须

类型

描述

[in] icon_info

TSDK_S_ICON_INFO*

自定义头像信息。

[out] update_time

TSDK_CHAR*

头像更改时间,空间由上层适配提供。

[io] length

TSDK_UINT32*

头像更新时间长度,传入时为空间大小,传出时为实际字串长度。

返回值

类型

描述

TSDK_RESULT

成功返回TSDK_SUCCESS,失败返回相应错误码。

代码示例

//OC
- (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_get_user_icon

接口描述

获取联系人头像。

注意事项

无。

方法定义

TSDK_API TSDK_RESULT tsdk_get_user_icon(IN TSDK_S_GET_ICON_PARAM *icon_param);
 

参数描述

参数名

是否必须

类型

描述

[in] icon_param

TSDK_S_GET_ICON_PARAM*

获取头像请求参数。

返回值

类型

描述

TSDK_RESULT

成功返回TSDK_SUCCESS,失败返回相应错误码。

代码示例

//OC
- (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);
}
 

tsdk_search_contacts

接口描述

搜索联系人。

注意事项

无。

方法定义

TSDK_API TSDK_RESULT tsdk_search_contacts(IN const TSDK_S_SEARCH_CONTACTS_PARAM* search_param);
 

参数描述

参数名

是否必须

类型

描述

[in] search_param

const TSDK_S_SEARCH_CONTACTS_PARAM*

搜索联系人请求参数。

返回值

类型

描述

TSDK_RESULT

成功返回TSDK_SUCCESS,失败返回相应错误码。

代码示例

//OC
- (void)searchContactWithParam:(SearchParam *)searchParam {
    TSDK_S_SEARCH_CONTACTS_PARAM *tsdkSearchParam = (TSDK_S_SEARCH_CONTACTS_PARAM *)malloc(sizeof(TSDK_S_SEARCH_CONTACTS_PARAM));
    memset(tsdkSearchParam, 0, sizeof(TSDK_S_SEARCH_CONTACTS_PARAM));
    if (searchParam.acSearchItem.length > 0 && searchParam.acSearchItem != nil) {
        strcpy(tsdkSearchParam->search_keyword, [searchParam.acSearchItem UTF8String]);
    }
    tsdkSearchParam->page_index = searchParam.ulPageIndex;
    tsdkSearchParam->is_exact_search = searchParam.ulExactSearch;
    
    if (searchParam.acDepId.length > 0 && searchParam.acDepId != nil && ![searchParam.acDepId isEqualToString:@"-1"])
    {
        strcpy(tsdkSearchParam->department_id, [searchParam.acDepId UTF8String]);
    }
    tsdkSearchParam->seq_no = searchParam.ulSeqNo;
    
    TSDK_RESULT result = tsdk_search_contacts(tsdkSearchParam);
    DDLogInfo(@"tsdk_search_contacts result: %d",result);
    free(tsdkSearchParam);
}