使用 Quickblox SDK 2.17 将视频作为附件发送
Send Video as Attachment with Quickblox SDK 2.17
我尝试了来自各种链接的代码,但不知何故似乎无法使用最新的 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
}
我想出了解决办法:
首先编写从图片库获取本地视频文件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)
})
}
这会将视频作为附件发送。
我尝试了来自各种链接的代码,但不知何故似乎无法使用最新的 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
}
我想出了解决办法:
首先编写从图片库获取本地视频文件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)
})
}
这会将视频作为附件发送。