Browse SDKs · iOS
Platform
SDKsiOS

Send a friend request

Send a friend request with OpenIM iOS SDK.

Copy

Dispatch a friend request to a target user using addFriend:reqMessage:onSuccess:onFailure:.

Parameters

ParameterTypeRequiredDescription
userIDNSString *YesTarget recipient user ID.
reqMessageNSString *NoOptional verification note or message. Pass an empty string @"" when omitted.

Code example

[[OIMManager manager] addFriend:@"user_b"
                     reqMessage:@"Hi, I'm Alex"
                      onSuccess:^(NSString *data) {
    [applicationStore markSentToUserID:@"user_b"];
}
                      onFailure:^(NSInteger code, NSString *message) {
    NSLog(@"addFriend failed: %ld %@", (long)code, message);
}];

Return value

The onSuccess callback confirms only that OpenIMServer accepted and routed the application; it does not indicate that the recipient accepted or that a friend relationship has formed.

State changes after the call

  • Local state merge: Record the pending outgoing request using userID as the unique entity key.
  • Outgoing history: To inspect all dispatched requests, invoke Retrieve sent friend requests.
  • Asynchronous event listening: When the recipient accepts or rejects the request, the sender receives notification callbacks through OIMFriendshipListener (see Retrieve received friend requests).