SDKsiOS
Block a user
Add a user to the current account’s blocklist with OpenIM iOS SDK.
Add a specified user to the authenticated account's blacklist using addToBlackList:ex:onSuccess:onFailure:.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userID | NSString * | Yes | Target user ID to blacklist. |
ex | NSString * | No | Custom extension string (e.g., JSON payload documenting reason or origin). Pass an empty string @"" when omitted. |
Code example
[[OIMManager manager] addToBlackList:targetUserID
ex:@"{\"source\":\"profile-menu\"}"
onSuccess:^(NSString *data) {
[blacklistStore addUserID:targetUserID];
}
onFailure:^(NSInteger code, NSString *message) {
NSLog(@"addToBlackList failed: %ld %@", (long)code, message);
}];Blacklisting is a unilateral relationship established by the local user. It suppresses incoming messages and direct interactions from the blocked user; it is distinct from channel-level mutes or system-wide account bans.
Return value
The onSuccess callback signifies that OpenIMServer recorded the blacklist relationship.
State changes after the call
- Local state merge: Insert or merge the newly blocked user into blacklist collections using
userIDas the unique entity key. - Asynchronous event listening: Linked devices observe blacklist changes in real time via
onBlackAdded:inOIMFriendshipListener. - Re-query calibration: To retrieve a full snapshot of all blocked accounts, invoke Retrieve the blocklist.
@interface BlacklistStore () <OIMFriendshipListener>
@end
@implementation BlacklistStore
- (void)startListening {
[[OIMManager callbacker] addFriendListener:self];
}
- (void)stopListening {
[[OIMManager callbacker] removeFriendListener:self];
}
- (void)onBlackAdded:(OIMBlackInfo *)info {
[self upsertBlackInfo:info];
}
@endRetain this listener instance strongly, and invoke removeFriendListener: when signing out or switching accounts.
Was this page helpful?