Skip to main content

Send messages

Chat UI's built-in channel pages provide functionality and UI for sending various message types (some message types require plugin support). When you need to send messages in custom pages, use the message sending methods in the Chat UI core class NCChatUI. These methods not only send messages but also trigger updates in Chat UI's built-in pages.

Chat UI supports sending regular messages and media messages (see message introduction). The parent class for regular messages is NCMessageContent, while the parent class for media messages is NCMediaMessageContent. The key difference between sending media messages and regular messages is whether there's a data upload process.

tip
  • Always use the message sending methods in Chat UI's core class NCChatUI, otherwise page updates won't be triggered.
  • Use sendMessageWithParams for regular messages and sendMediaMessageWithParams for media messages.
  • The Chat SDK enforces a rate limit of 5 messages per second.

Send regular messages

Before sending a message, construct an NCChatUISendMessageParams object. This object contains the regular message content to send, which must be a subclass of NCMessageContent, such as text messages (NCTextMessage).

When you call NCChatUI's message sending methods, the SDK triggers updates in the built-in channel list and channel pages.

Method signature

Objective C
- (void)sendMessageWithParams:(NCChatUISendMessageParams *)params
completion:(nullable void (^)(NCMessage * _Nullable message, NCError * _Nullable error))completion;

sendMessageWithParams allows controlling push notification content (pushContent) and push metadata (pushData) through params.pushConfig. For more granular control over push notifications (e.g., title, content, icon, or third-party vendor-specific configurations), use message push properties instead (see customize message push notifications). Note that open channels don't support offline messaging and therefore don't support offline-to-push conversion.

  • For SDK built-in message types like NCTextMessage, set params.pushConfig to nil. When these messages trigger push notifications, the server uses default pushContent values. See user content message formats for default push notification content by message type.
  • For custom message types requiring push notifications, you must provide pushContent, otherwise users won't receive push notifications.
  • For custom message types not requiring push notifications (e.g., app-level operation commands), leave pushContent empty.
  • params.pushConfig's pushContent and pushData can be configured directly in send parameters, offering additional capabilities like custom push titles. See customize message push notifications.

Parameters

ParameterTypeDescription
paramsNCChatUISendMessageParamsRequired message parameters including channel type (channelType), channel ID (channelId), and message content (content). See message introduction for message content structure.
pushContentNSStringCustomizes push notification content. Configure via params.pushConfig.pushContent (see configure message push properties).
  • For default push content, leave params.pushConfig unset or pushContent empty (note: custom message types have no defaults)
  • For per-message customized push notifications, provide pushContent
  • Custom message types requiring push must include pushContent
pushDataNSStringPush metadata. Configure via params.pushConfig.pushData or leave unset. See configure message push properties.
completionBlockCallback upon message send completion. Returns message object on success, NCError and message object on failure.

Example

Objective C
NCTextMessage *messageContent = [[NCTextMessage alloc] initWithText:@"Test text message"];

NCChatUISendMessageParams *params =
[[NCChatUISendMessageParams alloc] initWithContent:messageContent];
params.channelType = NCChannelTypeDirect;
params.channelId = @"targetId";

[[NCChatUI shared]
sendMessageWithParams:params
completion:^(NCMessage * _Nullable message, NCError * _Nullable error) {
if (error == nil) {
// Success
} else {
// Failure
}
}];

Send media messages

The content field in NCChatUISendMediaMessageParams must contain an NCMediaMessageContent subclass object representing media message content, such as image messages (NCImageMessage) or GIF messages (NCGIFMessage). Other built-in media message types include file messages (NCFileMessage), HD voice messages (NCHDVoiceMessage), and short video messages (NCShortVideoMessage) - we recommend integrating the corresponding Chat UI plugins first.

Image messages (NCImageMessage) support sending original quality images.

Use sendMediaMessageWithParams for media messages. The SDK generates thumbnails for images/videos, compresses them per default settings, uploads media files to the default file server, then sends the message after updating remote media URLs. Original quality images skip compression.

Calling NCChatUI's message sending methods triggers updates in built-in channel list and channel pages.

Method signature

Objective C
- (void)sendMediaMessageWithParams:(NCChatUISendMediaMessageParams *)params
progress:(nullable void (^)(int progress, NCMessage *progressMessage))progressBlock
completion:(nullable void (^)(NCMessage * _Nullable message, NCError * _Nullable error))completion
cancel:(nullable void (^)(NCMessage *cancelMessage))cancelBlock;

sendMediaMessageWithParams allows controlling push notifications through params.pushConfig, similar to regular messages. See customize message push notifications for advanced push configuration. Open channels don't support offline messaging.

Parameters

ParameterTypeDescription
paramsNCChatUISendMediaMessageParamsRequired message parameters including channel type (channelType), channel ID (channelId), and message content (content). See message introduction for message content structure.
pushContentNSStringCustomizes push notification content. Configure via params.pushConfig.pushContent (see configure message push properties). Same rules as regular messages apply.
pushDataNSStringPush metadata. Configure via params.pushConfig.pushData or leave unset. See configure message push properties.
progressBlockBlockMedia upload progress callback.
completionBlockCallback upon message send completion. Returns message object on success, NCError and message object on failure.
cancelBlockCallback when sending is canceled.

Example

Objective C
NCImageMessage *mediaMessageContent =
[[NCImageMessage alloc] initWithImageURI:@"path/to/image"];
mediaMessageContent.original = YES; // Send original quality image

NCChatUISendMediaMessageParams *params =
[[NCChatUISendMediaMessageParams alloc] initWithContent:mediaMessageContent];
params.channelType = NCChannelTypeDirect;
params.channelId = @"targetId";

[[NCChatUI shared] sendMediaMessageWithParams:params
progress:^(int progress, NCMessage *progressMessage) {
// Media upload progress
}
completion:^(NCMessage * _Nullable message, NCError * _Nullable error) {
if (error == nil) {
// Success
} else {
// Failure
}
}
cancel:^(NCMessage *cancelMessage) {
// Canceled
}];

To send an image that is already loaded in memory, initialize the message with UIImage:

Objective C
UIImage *image = [UIImage imageNamed:@"demo"];
NCImageMessage *mediaMessageContent = [[NCImageMessage alloc] initWithImage:image];
mediaMessageContent.original = YES;
tip

If media files are already uploaded (i.e., media messages have remote URLs), you can send them as regular messages.

Disable push notifications for messages

When recipients are offline, the server triggers push notifications by default (subject to app-level and user-level do-not-disturb settings).

Sometimes apps may want to prevent specific messages from triggering pushes. While Chat UI provides this capability, it's not exposed in the UI. To implement:

  1. Intercept messages via NCChatUI's messageInterceptor delegate (see message interception).

  2. Get the NCChatUISendMessageParams or NCChatUISendMediaMessageParams parameter object.

  3. Set disableNotification to YES to disable pushes for that message. Offline messages remain available via server cache (up to 7 days) for direct channels, group channels, and system channels.

    Objective C
    NCChatUISendMessageParams *params =
    [[NCChatUISendMessageParams alloc] initWithContent:someMsg];
    params.channelType = NCChannelTypeDirect;
    params.channelId = @"targetId";
    params.disableNotification = YES;
  4. Resend the message using the send methods.

Customize message push notifications

Chat UI supports per-message push customization (NCPushConfig) though not exposed in the UI. To implement, intercept messages during sending (same approach as disabling pushes).

NCPushConfig supports these capabilities (see configure message push properties in APNs push guide for details):

  • Custom push titles/contents
  • Custom notification icons
  • Additional push metadata
  • Force displaying notification content regardless of client settings
  • Other APNs/Android push channel customizations