聊天页面发送图片消息,将图片传到指定服务器的处理方法

如果需要将发送的图片消息中的图片传到自己的服务器,需要调用下面接口发送图片消息, appUpload:(BOOL)appUpload传入YES。

- (void)sendMediaMessage:(RCMessageContent *)messageContent

pushContent:(NSString *)pushContent

appUpload:(BOOL)appUpload;

重写下面方法,异步线程模拟了一个上传的过程,使用时请替换为自己上传图片的过程,当图片上传成功后得到图片的URL地址,将这个地址赋值给图片消息中的imageUrl属性,然后将图片消息对象传给uploadListener.successBlock()即可。

- (void)uploadMedia:(RCMessage *)message uploadListener:(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];

}

RCImageMessage *imageMsg = (RCImageMessage*)message.content;

imageMsg.imageUrl = @“http://www.rongcloud.cn/images/newVersion/bannerInner.png?0717”;

uploadListener.successBlock(imageMsg);

});

}