如何在快速blox iOS中将视频文件作为附件发送



Quickblox iOS 视频附件

我已将Quickblox iOS(Objc(库集成到我的聊天模块应用程序中。

QBRequest TUploadFile方法下,图像作为附件是可能的。但是我找不到任何可行的解决方案来在同一请求下制作视频附件文件。

我已经通过阅读快速博客中的文档进行了确认,该文档说 - 在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);
        }
    }];
}

您可以使用以下方法发送视频。

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

相关内容

  • 没有找到相关文章

最新更新