开发者在只集成了IMLib
的情况下,如果需要将媒体消息上传到自己的服务器,可以通过实现下面的方法来实现
- (RCMessage *)sendMediaMessage:(RCConversationType)conversationType
targetId:(NSString *)targetId
content:(RCMessageContent *)content
pushContent:(NSString *)pushContent
pushData:(NSString *)pushData
uploadPrepare:(void (^)(RCUploadMediaStatusListener *uploadListener))uploadPrepareBlock
progress:(void (^)(int progress, long messageId))progressBlock
success:(void (^)(long messageId))successBlock
error:(void (^)(RCErrorCode errorCode, long messageId))errorBlock
cancel:(void (^)(long messageId))cancelBlock;
代码示例:
RCMessage *rcMessage = [[RCIMClient sharedRCIMClient] sendMediaMessage:conversationType
targetId:targetId
content:messageContent
pushContent:pushContent
pushData:@""
uploadPrepare:^(RCUploadMediaStatusListener *uploadListener) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// 进行上传 此处模仿上传进度
int i = 0;
for (i = 0; i < 100; i++) {
//回调上传进度
uploadListener.updateBlock(i);
[NSThread sleepForTimeInterval:0.2];
}
//上传结果处理写在对应处理位置
//如果上传成功则参考下面赋值并回调(此处以图片消息为例)
messageContent.imageUrl = @"http://www.rongcloud.cn/images/newVersion/bannerInner.png?0717";
uploadListener.successBlock(messageContent);
//如果上传失败则回调 RCErrorCode errorCode :上传失败的错误码,非0整数
//uploadListener.errorBlock(errorCode);
//如果取消上传则回调
//uploadListener.cancelBlock();
});
}
progress:^(int progress, long messageId) {
}
success:^(long messageId) {
}
error:^(RCErrorCode errorCode, long messageId) {
}
cancel:^(long messageId) {
}];