Browse SDKs · iOS
Platform
SDKsiOS

Send a message

Send a prepared message object with OpenIM iOS SDK.

Copy

Invoke sendMessage:recvID:groupID:isOnlineOnly:offlinePushInfo:onProgress:onSuccess:onFailure: on OIMManager to dispatch a prepared message object to a user or group conversation. For rich media messages, the SDK manages local database insertion and object storage uploads while notifying progress callbacks:

Parameters

ParameterTypeRequiredDescription
messageOIMMessageInfo *YesPrepared message object created by factory methods.
recvIDNSString *ConditionalReceiver user ID for one-to-one chats. Required for single chat; pass nil for group messages.
groupIDNSString *ConditionalTarget group ID for group chats. Required for group chat; pass nil for single messages. recvID and groupID are mutually exclusive.
isOnlineOnlyBOOLYesWhether the message is delivered to online users only. Set to YES to bypass offline storage and push notifications; normally set to NO.
offlinePushInfoOIMOfflinePushInfo *NoCustom offline push configuration including title, description, and pass-through payload. Pass nil for defaults.
onProgressOIMNumberCallbackNoUpload progress callback returning values from 0 to 100. Non-media messages do not trigger this callback.
onSuccessvoid (^)(OIMMessageInfo *sent)YesSuccess callback returning the confirmed message model.
onFailureOIMFailureCallbackYesFailure callback returning error code code and descriptive message msg.

Code example

[[OIMManager manager] sendMessage:message
                           recvID:receiverUserID
                          groupID:nil
                     isOnlineOnly:NO
                  offlinePushInfo:nil
                       onProgress:^(NSInteger progress) {
    // Rich media upload progress (0 to 100)
    [messageStore updateProgress:progress clientMsgID:message.clientMsgID];
}
                        onSuccess:^(OIMMessageInfo *sent) {
    // Delivery succeeded; merge confirmed message by clientMsgID
    if (sent != nil) {
        [messageStore upsert:sent];
    }
}
                        onFailure:^(NSInteger code, NSString * _Nullable msg) {
    // Handle message delivery failure
}];

Return value

The onSuccess callback receives the confirmed OIMMessageInfo model returned by the server. The client merge key is clientMsgID (scoped to conversationID when organizing multi-conversation caches).

State changes after the call

  1. Local write and upload: Sending rich media initiates local database insertion, asset uploading with progress notifications, and subsequent network dispatch.
  2. Delivery confirmation vs receipt: Success callback confirms that the server accepted the message. Counterparty arrival notifications and history queries represent distinct synchronization stages.
  3. Incoming message handling: For incoming message event listeners and UI update flows, see Receive messages.