QuickBlox Documentation

QuickBlox provides powerful Chat API and SDK to add real-time messaging and video calls to your web and mobile apps. Learn how to integrate QuickBlox across multiple platforms.

Users

Learn how to manage your users with QuickBlox.

The user module manages all things related to user accounts handling, authentication, account data, password remind, etc.

Before you begin

  1. Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
  2. Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
  3. Configure QuickBlox SDK for your app. Check out our Setup page for more details.
  4. Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.

Create user

Create a user using the code snippet below. Only login (or email) and password are required. Other fields are optional.

let user = QBUUser()
user.login = "myLogin"
user.fullName = "myFullName"
user.password = "myPassword"

QBRequest.signUp(user, successBlock: { (response, user) in

}, errorBlock: { (response) in

})
QBUUser *user = [[QBUUser alloc] init];
user.login = @"myLogin";
user.fullName = @"myFullName";
user.password = @"myPassword";

[QBRequest signUp:user successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull user) {
        
} errorBlock:^(QBResponse * _Nonnull response) {

}];

Update user

Update a user profile using the following code snippet. If you want to change your password, you need to provide 2 parameters: password and oldPassword. An updated user entity will be returned. If you want to update any other fields of the user (e.g. e-mail or full name), you can do it by calling updateCurrentUser() method.

let updateUserParameter = QBUpdateUserParameters()
updateUserParameter.fullName = "newFullName"

QBRequest.updateCurrentUser(updateUserParameter, successBlock: {response, user in

}, errorBlock: { (response) in

})
QBUpdateUserParameters *updateParameters = [[QBUpdateUserParameters alloc] init];
updateParameters.fullName = @"newFullName";
    
[QBRequest updateCurrentUser:updateUserParameter successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull user) {

} errorBlock:^(QBResponse * _Nonnull response) {

}];

🚧

You must set null into the user's password field if you do not want to change your password, otherwise, you will need to add the user's old password to the oldPassword field.

Set user avatar

You can set a user's avatar. You just need to upload it to the QuickBlox cloud storage and then connect to the user.

let image = ...
guard let imageData = image.pngData() else {
    return
}
QBRequest.tUploadFile(imageData, fileName: "avatar.png", contentType: "image/png", isPublic: true, successBlock: { (response, uploadedBlob) in
    
    let parameters = QBUpdateUserParameters()
    let customData = ["avatar_uid" : uploadedBlob.uid]
    guard let customJSONData = try? JSONSerialization.data(withJSONObject:  customData, options: .prettyPrinted) else { return }
    parameters.customData = String(data: customJSONData, encoding: .utf8)
    QBRequest.updateCurrentUser(parameters, successBlock: { (response, user) in
        //updated user
    }, errorBlock: { (response) in
        //show update user error
    })
    
}, statusBlock: { (request, status) in
    //show upload progress
}, errorBlock: { (response) in
    //show upload error
})
UIImage *image = ...
NSData *imageData = UIImagePNGRepresentation(image);

[QBRequest TUploadFile:imageData fileName:@"avatar.png" contentType:@"image/png" isPublic:TRUE successBlock:^(QBResponse * _Nonnull response, QBCBlob * _Nonnull uploadedBlob) {
    
    NSDictionary *customData = @{@"avatar_uid" : uploadedBlob.UID};
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:customData options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonCustomData = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    QBUpdateUserParameters *parameters = [[QBUpdateUserParameters alloc] init];
    parameters.customData = jsonCustomData;
    
    [QBRequest updateCurrentUser:parameters successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull user) {
        //updated user
    } errorBlock:^(QBResponse * _Nonnull response) {
        //show update user error
    }];
    
} statusBlock:^(QBRequest * _Nonnull request, QBRequestStatus * _Nonnull status) {
    //show upload progress
} errorBlock:^(QBResponse * _Nonnull response) {
    //show upload error
}];

Now, other users can get your avatar.

let user = ...
if let data = user.customData?.data(using: .utf8),
    let customData = try? JSONSerialization.jsonObject(with: data, options: []) as! [String : String],
    let avatarUID = customData["avatar_uid"] {
    
    QBRequest.downloadFile(withUID: avatarUID, successBlock: { (response, fileData)  in
        if let image = UIImage(data: fileData) {
            //set user avatar image
            userAvatarImageView.image = image
        }
    }, statusBlock: { (request, status) in
        //show download progress
    }, errorBlock: { (response) in
        //show download error
    })
}
NSData *jsonData = [user.customData dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *customData = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
NSString *avatarUDID = customData[@"avatar_uid"];

[QBRequest downloadFileWithUID:avatarUDID successBlock:^(QBResponse * _Nonnull response, NSData * _Nonnull fileData) {
    UIImage *image = [UIImage imageWithData:fileData];
    //set user avatar image
    userAvatarImageView.image = image;
    
} statusBlock:^(QBRequest * _Nonnull request, QBRequestStatus * _Nonnull status) {
    //show download progress
} errorBlock:^(QBResponse * _Nonnull response) {
    //show download error
}];

Retrieve users

Retrieve users by ID

To get a list of users by ID for a current account, use the following code snippet.

let page = QBGeneralResponsePage(currentPage: 5, perPage: 10)      
QBRequest.users(withIDs: ["21","22"], page: page, successBlock: { (response, page, users) in
     
}, errorBlock:{ (response) in
    
})
QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:5 perPage:10];
[QBRequest usersWithIDs:@[@"20", @"21"] page:page successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
       
} errorBlock:^(QBResponse * _Nonnull response) {
                       
}];

Retrieve user by login

To get a list of users by login for a current account, use the following code snippet.

QBRequest.user(withLogin: "amigo", successBlock: { (response, user) in
    
}, errorBlock: { (response) in
    
})
[QBRequest userWithLogin:@"amigo" successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull user) {
                
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Retrieve user by email

To get a list of users by email for a current account, use the following code snippet.

QBRequest.user(withEmail: "[email protected]", successBlock: { (response, user) in

}, errorBlock: { (response) in

})
[QBRequest userWithEmail:@"[email protected]" successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull user) {
               
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Retrieve users by full name

To get a list of users found by the server according to the search query, use the following code snippet.

QBRequest.users(withFullName: "Amigo", page: nil, successBlock: { (response, page, users) in
       
}, errorBlock: { (response) in

})
[QBRequest usersWithFullName:@"Amigo" page:nil successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
                   
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Retrieve users by phone number

To get a list of users by phone number for a current account, use the following code snippet.

QBRequest.users(withPhoneNumbers: ["+4427123314"], page: nil, successBlock: { (response, page, users) in
   
}, errorBlock: { (response) in
    
})
[QBRequest usersWithPhoneNumbers:@[@"+4427123314"] page:nil successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
             
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Retrieve user by external user ID

If you have your own database with users (we call these databases as "external databases"), you can use External User IDExternal User ID - a unique identifier of the user in the integrated external system; used for cross-referencing. For example, a user has an internal user ID within the QuickBlox system and external ID, provided by the integrated external (client) system. When an API call with reference to the user has to be submitted, the user can be referenced by either internal or external identifiers. (ExternalID field) in QBUser model to link users from QuickBlox with users from your external database.

QBRequest.user(withExternalID: 3789, successBlock: { response, user in
    
}, errorBlock: { (response) in
    
})
[QBRequest userWithExternalID:3789 successBlock:^(QBResponse * _Nonnull response, QBUUser *user) {
    
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Retrieve users by tags

To get a list of users by tags for a current account, use the following code snippet.

QBRequest.users(withTags: ["iphone"], page: nil, successBlock: { (response, page, users) in
   
}, errorBlock: { (response) in

})
[QBRequest usersWithTags:@[@"iphone"] page:nil successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
             
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Delete user

A user can delete himself from the platform.

QBRequest.deleteCurrentUser(successBlock: { (response) in
    
}, errorBlock: { (response) in
    
})
[QBRequest deleteCurrentUserWithSuccessBlock:^(QBResponse * _Nonnull response) {
    
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Reset user password

It's possible to reset a password via email.

QBRequest.resetUserPassword(withEmail: "[email protected]", successBlock: { (response) in
            
}, errorBlock: { (response) in
               
})
[QBRequest resetUserPasswordWithEmail:@"[email protected]" successBlock:^(QBResponse * _Nonnull response) {

} errorBlock:^(QBResponse * _Nonnull response) {

}];

📘

By default, a password reset functionality is turned off for Basic, Startup and Growth plans. Contact the sales team.

Updated 4 months ago


What's Next

Chat

Users


Learn how to manage your users with QuickBlox.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.