logo
On this page

Blacklist management


Note

Blacklisting and friend operations do not affect each other. Taking user A and B as friends as an example:

  1. User A can blacklist user B, but they will still be friends.
  2. If at this point, user A and user B end their friendship, user B will still be on user A's blacklist.
  3. Afterwards, if user A removes user B from the blacklist, user B will still not be user A's friend.

Function Introduction

You can check your blacklist, blacklist a specified user (no longer receiving messages from that user), move out of the blacklist, and check if a specified user is in the blacklist.

Implementation Process

Query Blacklist

After logging in to the ZIM SDK, users can query the blacklist by using the queryBlacklistWithConfig interface.

The query result is returned through the ZIMBlacklistQueriedCallback.

Sample code
// Query the blocklist.
ZIMBlacklistQueryConfig *config = [[ZIMBlacklistQueryConfig alloc] init];
// Enter the number of blocked users to be queried per time.
config.count = 100;
// Enter the flag for a paginated pull.
config.nextFlag = 0;
[[ZIM getInstance] queryBlacklistWithConfig:config callback:^(NSArray<ZIMUserInfo *> * _Nonnull blacklist, unsigned int nextFlag, ZIMError * _Nonnull errorInfo) {
    if(errorInfo.code == ZIMErrorCodeSuccess){
        // Obtain the blocklist from the `blacklist` field.
    }
}];
1
Copied!

Block Users

After logging in to the ZIM SDK, users can call the addUsersToBlacklistWithUserIDs interface to add specified users to the blacklist.

The result of blocking users is returned through the ZIMBlacklistUsersAddedCallback.

Warning
  • Up to 20 users can be blocked with one API call. Exceeding the limit will cause the API call to fail.
  • The default maximum number of blacklisted users is 1000. If you need to increase it, please contact ZEGOCLOUD technical support.
Sample code
// Block user "zegocloud".
NSArray *userIDs = @[@"zegocloud"];
[[ZIM getInstance] addUsersToBlacklistWithUserIDs:userIDs callback:^(NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
    if(errorInfo.code == ZIMErrorCodeSuccess){
        // The information of users who fail to be blocked is returned in the `errorUserList` field.
    }
}];
1
Copied!

Unblock Users

After logging in to the ZIM SDK, users can call the removeUsersFromBlacklistWithUserIDs interface to remove specified users from the blacklist.

The unblock operation will be returned through the ZIMBlacklistUsersRemovedCallback .

Warning

Up to 20 users can be removed with one API call. Exceeding the limit will cause the API call to fail.

Sample code
// Unblock user "zegocloud".
NSArray *userIDs = @[@"zegocloud"];
[[ZIM getInstance] removeUsersFromBlacklistWithUserIDs:userIDs callback:^(NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo)     {
    if(errorInfo.code == ZIMErrorCodeSuccess){
        // The information of users who fail to be unblocked is returned in the `errorUserList` field.
    }
}];
1
Copied!

Check if the user is in the blacklist

After logging in to the ZIM SDK, users can call the checkUserIsInBlackListByUserID interface to check if a specified user is in their blacklist.

The result of the check operation is returned through the ZIMBlacklistCheckedCallback.

Sample code
// Check whether user "zegocloud" is in the blocklist. 
[[ZIM getInstance] checkUserIsInBlackListByUserID:@"zegocloud" callback:^(BOOL isUserInBlacklist, ZIMError * _Nonnull errorInfo) {
    if(errorInfo.code == ZIMErrorCodeSuccess) {
            // The `isUserInBlacklist` parameter indicates whether the user is in the blocklist. Valid values: `true`: yes; `false`: no.
    }
}];
1
Copied!

Previous

Offline login

Next

Friend management