选择图片并上传

业务场景

适用于 CP 编写自定义客诉 UI 页面时,需要选择图片并上传,用于用户提交客服工单。

详细业务说明请看客服-客服工单

注意事项

  • 用户从相册中选择图片,并将图片转换为 base64 字符串,用于后续提交客服工单。

流程说明

接口介绍

/**
 * 选择图片并上传
 *
 */
- (void)selectImage:(SelectImageConfig *)imageData

调用示例

// 监听回调通知
// 上传图片成功回调通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUpImageSuccess:) name:NOTIFICATION_GETUPIMAGE_SUCCESS object:nil];
// 上传图片失败回调通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUpImageFailed:) name:NOTIFICATION_GETUPIMAGE_FAILED object:nil];


// 接口调用
SelectImageConfig *config = [[SelectImageConfig alloc]init];
// 图片压缩质量百分比, 默认100
config.quality = 100;
// 压缩和转换url过程是否显示SDK的loading动画, 默认false
config.showLoading = false;
// 是否转换为url, 默认true
config.withUrl = true;
[[SDKManager getInstance] selectImage:config];

// 回调方法
- (void)onUpImageSuccess:(NSNotification *)notif
{
    NSDictionary *ImageData = notif.userInfo;
    NSData *bitmap = BindStatusInfo[KEY_IMAGEDATA];
    NSString *url = BindStatusInfo[KEY_IMAGEPATH]; // 图片转换为url,用于后续提交客服工单
    [self textViewLog:@"图片上传成功"];
}

- (void)onUpImageFailed:(NSNotification *)notif
{
    NSDictionary *errorInfo = notif.userInfo;
    NSInteger errorCode = [[errorInfo objectForKey:KEY_ERROR_CODE] integerValue];
    NSString *errorMsg = [errorInfo objectForKey:KEY_ERROR_MSG];
    [self textViewLog:[NSString stringWithFormat:@"图片上传失败: %@(%ld)", errorMsg, errorCode]];
}

参数说明

入参:SelectImageConfig

参数名称类型说明备注
qualityNSInteger压缩质量, 默认 100可选
withUrlBOOL是否转换成 url, 默认 true可选
showLoadingBOOL是否显示 loading 动画, 默认 true可选

出参:ImageData data

参数名称类型说明
imageBase64NSString图片的 base64 数据
urlNSStringurl

错误码

FAQ