Browse SDKs · iOS
Platform
SDKsiOS

Accept a friend request

Accept a friend request with OpenIM iOS SDK.

Copy

Accept a friend request from an applicant to establish mutual friendship using acceptFriendApplication:handleMsg:onSuccess:onFailure:.

Parameters

ParameterTypeRequiredDescription
userIDNSString *YesThe applicant user ID who initiated the friend request.
handleMsgNSString *NoOptional acceptance note (e.g., @"Accepted"). Pass an empty string @"" when omitted.

Code example

[[OIMManager manager] acceptFriendApplication:applicantUserID
                                     handleMsg:@"Accepted"
                                     onSuccess:^(NSString *data) {
    [applicationStore markAcceptedForUserID:applicantUserID];
}
                                     onFailure:^(NSInteger code, NSString *message) {
    NSLog(@"acceptFriendApplication failed: %ld %@", (long)code, message);
}];

Return value

The onSuccess callback signifies that OpenIMServer processed the acceptance and established mutual friendship on the server.

State changes after the call

  • Local state merge: Merge application resolution state using userID as the unique entity key.
  • Application updates: The application record updates via onFriendApplicationAccepted: in OIMFriendshipListener (see Retrieve received friend requests).
  • Friend addition: The new friendship record arrives via onFriendAdded: in OIMFriendshipListener (see Retrieve the friend list by page), where the client merges the new contact by userID.