我已将Quickblox iOS(Objc)库集成到我的聊天模块应用程序中。
作为 QBRequest TUploadFile 方法下的附件的图像是可能的。但我找不到任何有效的解决方案来制作同一请求下的视频附件。
我已经通过阅读Quickblog中的文件证实了这一点 - 在Quickblox聊天SDK下可以使用视频附件。
有没有人有任何工作解决方案来制作视频文件?
下面的代码用于在 QBRequest TUploadFile 下上传视频。
提前致谢!
- (void)uploadAndSendAttachmentMessage:(QBChatMessage*)message toDialog:(QBChatDialog*)dialog withChatService:(QMChatService*)chatService withAttachedVideo:(NSData*)videoData completion:(QBChatCompletionBlock)completion {
[self changeMessageAttachmentStatus:QMMessageAttachmentStatusLoading forMessage:message];
[QBRequest TUploadFile:videoData fileName:@"attachment video" contentType:@"video/mp4" isPublic:YES successBlock:^(QBResponse* response, QBCBlob* blob) {
QBChatAttachment* attachment = [QBChatAttachment new];
attachment.type = @"video";
attachment.ID = blob.UID;
attachment.url = [blob publicUrl];
message.attachments = @[attachment];
message.text = @"Attachment video";
[self saveData:videoData chatAttachment:attachment error:nil];
[self.attachmentsStorage setObject:videoData forKey:attachment.ID];
[self changeMessageAttachmentStatus:QMMessageAttachmentStatusLoaded forMessage:message];
[chatService sendMessage:message type:QMMessageTypeText toDialog:dialog saveToHistory:YES saveToStorage:YES completion:completion];
} statusBlock:^(QBRequest* request, QBRequestStatus* status) {
if ([self.delegate respondsToSelector:@selector(chatAttachmentService:didChangeUploadingProgress:forMessage:)]) {
[self.delegate chatAttachmentService:self didChangeUploadingProgress:status.percentOfCompletion forMessage:message];
}
} errorBlock:^(QBResponse* response) {
[self changeMessageAttachmentStatus:QMMessageAttachmentStatusNotLoaded forMessage:message];
if (completion) {
completion(response.error.error);
}
}];
}
答案 0 :(得分:0)
您可以使用以下方法发送视频。
- (void)sendAttachmentMessage:(QBChatMessage *)attachmentMessage
toDialog:(QBChatDialog *)dialog
withAttachment:(QBChatAttachment *)attachment
completion:(nullable QBChatCompletionBlock)completion
完整的代码如下所示
- (void)didPickAttachmentVideo:(NSURL *)video {
QBChatMessage *message = [QBChatMessage new];
message.senderID = self.senderID;
message.dialogID = self.dialog.ID;
message.dateSent = [NSDate date];
__weak typeof(self)weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
__typeof(weakSelf)strongSelf = weakSelf;
QBChatAttachment *attachment = [QBChatAttachment videoAttachmentWithFileURL:video];
// Sending attachment to the dialog.
dispatch_async(dispatch_get_main_queue(), ^{
[self.chatDataSource addMessage:message];
[[ServicesManager instance].chatService sendAttachmentMessage:message
toDialog:strongSelf.dialog
withAttachment:attachment
completion:^(NSError *error) {
[strongSelf.attachmentCells removeObjectForKey:message.ID];
NSString * myurl = attachment.remoteURL.absoluteString;
if (error != nil) {
[strongSelf.chatDataSource deleteMessage:message];
//Show error alert
}
}];
});
});
}