使用 Quickblox SDK 2.17 将视频作为附件发送

Posted

技术标签:

【中文标题】使用 Quickblox SDK 2.17 将视频作为附件发送【英文标题】:Send Video as Attachment with Quickblox SDK 2.17 【发布时间】:2018-07-24 11:24:50 【问题描述】:

我尝试了来自各种链接的代码,但不知何故,最新的 SDK 似乎没有任何效果。 我正在尝试使用以下代码:

let message = QBChatMessage()
message.senderID = (self.senderID)
message.dialogID = self.chatDialogModel.id
message.dateSent = Date()
message.readIDs = [NSNumber.init(value: (self.senderID))]
message.deliveredIDs = [NSNumber.init(value: (self.senderID))]

let aURL = Bundle.main.url(forResource: "testVideo", withExtension:"mp4")
let aData = try! Data(contentsOf: aURL!)

QBRequest.tUploadFile(aData, fileName: "Attachment Video", 
                     contentType:"video/mp4", 
                     isPublic: true, successBlock:  (qbResponse, qbBlob) in

   let attachment : QBChatAttachment = QBChatAttachment()
    attachment.type = "video"
    attachment.id = qbBlob.uid
    attachment.url = qbBlob.publicUrl()
    message.attachments = [attachment]
    message.text = "Attachment video"

    self.chatDataSource.add(message)


ServicesManager.instance().chatService.sendAttachmentMessage(message, to: (self.chatDialogModel)!, with: attachment, completion:  [weak self] (error) -> Void in


  self?.attachmentCellsMap.removeObject(forKey: message.id as AnyObject?)
  guard error != nil else  return 
  self?.chatDataSource.delete(message)

 )

, statusBlock: nil)  (error) in


【问题讨论】:

【参考方案1】:

我想出了一个解决办法:

首先编写从图片库中获取本地视频文件URL的代码。获得 url 后,调用此函数。

func sendVideoAsAttachment(_ url : URL)

    let message = QBChatMessage()
    message.senderID = (self.senderID)
    message.dialogID = self.chatDialogModel.id
    message.dateSent = Date()

    let attachment = QBChatAttachment.videoAttachment(withFileURL: url)
    self.chatDataSource.add(message)

    ServicesManager.instance().chatService.sendAttachmentMessage(message, to: self.chatDialogModel, with: attachment, completion:  (error) in

        self.attachmentCellsMap.removeObject(forKey: message.id as AnyObject?)
        guard error != nil else  return 
        self.chatDataSource.delete(message)
    )

这会将视频作为附件发送。

【讨论】:

以上是关于使用 Quickblox SDK 2.17 将视频作为附件发送的主要内容,如果未能解决你的问题,请参考以下文章

quickblox javascript sdk 一对一视频聊天

为啥只能在 Android SDK QuickBlox 上进行第一次视频通话?

在集成 Quickblox SDK 时限制发送状态的数量

无法将 Quickblox Sdk 2.4 指向或配置到 android 应用程序中的新(跟踪)实例

Quickblox Flutter SDK 示例 WebRTC 未连接

无需 SDK 将文件上传到 Quickblox,最好使用 Alamofire