Search code examples
iosobjective-cswiftquickblox

How to get sender profile image from quickblox in swift?


I am using QBChatMessage to get all messages sent in the chat.

I have uploaded the user's image in admin panel of quickblox. Now, i am facing problem in getting the image from quickblox contents.

If anyone knows, please help me. As I have already tried getting the user image using message.senderID but it is not succeeding.


Solution

  • Have you tried this approach? First of all you should get user by id, and then check his avatarURl and blobID

            QBRequest.userWithID(message.senderID, successBlock: { (response :QBResponse?, user:QBUUser?) in
    
            if user?.avatarUrl == nil {
    
                //no avatar. Download file by user's blob id
                let userProfileBlobUID = user?.blobID
                QBRequest.downloadFileWithID(UInt(userProfileBlobUID!), successBlock: { (response : QBResponse,imageData: NSData) in
    
                    let image = UIImage(data:imageData)
    
                    }, statusBlock: nil, errorBlock: nil)
            }
            else {
                //download image by url
            }
    
        }) { (response :QBResponse) in
    
        }