Browse SDKs · iOS
Platform
SDKsiOS

Create a contact-card message

Create a user contact-card message with OpenIM iOS SDK.

Copy

Invoke createCardMessage: on OIMMessageInfo to construct a contact-card message object that recommends a user profile to the counterparty:

Parameters

ParameterTypeRequiredDescription
cardElemOIMCardElem *YesContact-card element model containing recommended user attributes.

Properties of OIMCardElem

ParameterTypeRequiredDescription
userIDNSString *YesUser ID of the recommended contact.
nicknameNSString *NoDisplay nickname of the recommended contact snapshot.
faceURLNSString *NoAvatar URL of the recommended contact snapshot.
exNSString *NoCustom business extension string.

Code example

OIMCardElem *card = [OIMCardElem new];
card.userID = @"user_b";
card.nickname = @"Alex";
card.faceURL = @"https://example.com/avatar.png";
card.ex = @"";

OIMMessageInfo *message = [OIMMessageInfo createCardMessage:card];

Return value

Returns an initialized OIMMessageInfo model with its content type set to contact card.

State changes after the call

  1. Local memory instantiation: This method constructs an in-memory message object without writing to the database or initiating network requests.
  2. Snapshot nature: The nickname and avatar inside the card element are snapshot values at message creation time. Subsequent updates to the user's profile will not automatically mutate historical card messages.
  3. Subsequent dispatch: Call Send a message to deliver the card message.