SDKsiOS
Send a friend request
Send a friend request with OpenIM iOS SDK.
Dispatch a friend request to a target user using addFriend:reqMessage:onSuccess:onFailure:.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userID | NSString * | Yes | Target recipient user ID. |
reqMessage | NSString * | No | Optional 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
userIDas 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).
Was this page helpful?