logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Manage users

Note

This document applies to the following platforms: iOS, Android, macOS, Windows and Web.

ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of user management, allows users to update their personal profile, such as username, and status updates.

Implementation Process

Manage the extended field

The ZIM SDK provides user extended fields to describe additional properties of users. Developers can use extended fields to customize user attributes through the updateUserExtendedData interface. The usage of extended fields can be defined by developers, and the SDK will only pass the fields without any further processing.

After modifying the extended field properties, users can receive the modification results through ZIMUserExtendedDataUpdatedResult.

Example
// Modify user information extension fields
String newUserExtendedData = "{\"user_avatar\":\"https://url\",\"user_name\":\"new_name\",\"user_sex\":\"male\",\"user_birth\":\"1970-01-01\",\"user_phone\":\"12345678901\"}";

try {
    ZIMUserExtendedDataUpdatedResult result =
        await ZIM.getInstance()!.updateUserExtendedData(newUserExtendedData);
    
    } on PlatformException catch (onError) {
        //Here is the logic of write operation failure according to the return value of onError
    }
1
Copied!

Modify User Name

The user name userName is a string used to describe the user's nickname. Developers can configure it through the ZIMUserInfo object. The ZIM SDK supports users to modify their user names after logging in through the updateUserName interface.

After modifying the user name, users can receive the modification results through ZIMUserNameUpdatedResult.

Example
// modify user name
// userName A string of up to 256 bytes, with no special character restrictions.
try {
    ZIMUserNameUpdatedResult result =
        await ZIM.getInstance()!.updateUserName('userName');
        //The logic of successful modification is written here
    } on PlatformException catch (onError) {
        // Write and modify the failure logic according to onError
    }
1
Copied!

Set User Avatar

The ZIM SDK supports users to set or modify their avatars after logging in through the updateUserAvatarUrl interface.

After setting the user avatar, users can receive the setting results through the ZIMUserAvatarUrlUpdatedResult.

Warning

When a user modifies his/her avatar, other users need to call the queryUsersInfo interface and set the isQueryFromServer parameter in ZIMUsersInfoQueryConfig to true to re-query the user information to obtain the latest avatar.

Example
// modify user name
// userAvatarUrl A string of up to 500 bytes, with no special character restrictions.
try {
    ZIMUserAvatarUrlUpdatedResult result =
        await ZIM.getInstance()!.updateUserAvatarUrl('userAvatarUrl');
        //The logic of successful modification is written here
    } on PlatformException catch (onError) {
        // Write and modify the failure logic according to onError
    }
1
Copied!

Query User Information

Users can query the full information of specified users, including user names and user extended fields, through the queryUsersInfo interface. Only in this interface can users obtain user avatar URLs and user extended field information.

After querying the information, users can receive the query results through the ZIMUsersInfoQueriedResult.

Example
// Query user information
// Usage restrictions: The number of UserID queries in a single API call cannot exceed 10; within 10 seconds, the cumulative total number of UserID queries in multiple API calls cannot exceed 10.
try {
    ZIMUserInfoQueryConfig config = ZIMUserInfoQueryConfig();
    config.isQueryFromServer = false; // Set to true if querying from the server, set to false if querying from local data
    ZIMUsersInfoQueriedResult result =
        await ZIM.getInstance()!.queryUsersInfo(['userID_1', 'userID_2'], config);
        // Write logic for successful query here
    } on PlatformException catch (onError) {
        // Write logic for failed query based on onError
    }
1
Copied!

Previous

Authentication

Next

Multi-device login