user3269516
user3269516

Reputation: 59

How to implement sending images in quickblox (Swift, iOS, xcode)

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

Answers (1)

Rafał Sroka
Rafał Sroka

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

Related Questions