Reputation: 59
I have an app already, and implemented Quickblox. So far, I only have message sending. How can I add sending images?
Upvotes: 2
Views: 619
Reputation: 40028
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object.
var imageData: NSData = UIImagePNGRepresentation(UIImage(named: "arrow.png")!)!
QBRequest.TUploadFile(imageData, fileName: "arrow.png", contentType: "image/png", isPublic: false, successBlock: {(response: QBResponse!, uploadedBlob: QBCBlob!) in
// Create and configure message
var message: QBChatMessage = QBChatMessage()
var uploadedFileID: UInt = uploadedBlob.ID
var attachment: QBChatAttachment = QBChatAttachment()
attachment.type = "image"
attachment.ID = String(uploadedFileID)
message.attachments = [attachment]
// Send message
}, statusBlock: {(request: QBRequest?, status: QBRequestStatus?) in
}, errorBlock: {(response: QBResponse!) in
NSLog("error: %@", response.error)
})
There is a fully working demo project that does what your looking for here.
Upvotes: 2