Send a message
Send messages to direct channels, group channels, and open channels.
Message content types
| Type | Class | Base class | Description |
|---|---|---|---|
| Text | NCTextMessage | NCMessageContent | Plain text |
| Reference reply | NCReferenceMessage | NCMessageContent | Quoted reply |
| Image | NCImageMessage | NCMediaMessageContent | Image (supports original) |
| GIF | NCGIFMessage | NCMediaMessageContent | Animated GIF |
| File | NCFileMessage | NCMediaMessageContent | File attachment |
| Voice | NCVoiceMessage | NCMediaMessageContent | HD voice |
| Mention (@) | N/A | N/A | Not a standalone type — see below |
- Use
sendMessagefor regular messages andsendMediaMessagefor media messages. - Rate limit: max 5 messages per second.
Send a regular message
Messages are sent through a channel instance. In Swift, create the channel, build SendMessageParams, and call sendMessage. The Objective-C equivalent is included below.
- Swift
- Objective-C
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else {
return
}
let textContent = TextMessage(text: "Hello")
let params = SendMessageParams(content: textContent)
channel.sendMessage(
params: params,
attachedHandler: { message in
// Message persisted locally — update UI here
},
completionHandler: { message, error in
if let error {
print("Send failed: \(error.localizedDescription)")
} else {
print("Sent successfully: \(message?.messageId ?? "")")
}
}
)
// Get a direct channel instance (use NCGroupChannel for group, NCOpenChannel for open channel)
NCDirectChannel *channel = [[NCDirectChannel alloc] initWithChannelId:@"targetUserId"];
// Build message content
NCTextMessage *textContent = [[NCTextMessage alloc] initWithText:@"Hello"];
// Build send parameters
NCSendMessageParams *params = [[NCSendMessageParams alloc] initWithContent:textContent];
// Send
[channel sendMessageWithParams:params
attachedHandler:^(NCMessage *message) {
// Message persisted locally — update UI here
} completionHandler:^(NCMessage *message, NCError *error) {
if (error) {
NSLog(@"Send failed: %@", error.localizedDescription);
} else {
NSLog(@"Sent successfully");
}
}];
NCSendMessageParams properties:
| Property | Type | Default | Description |
|---|---|---|---|
content | NCMessageContent * | — | Message content (required) |
directedUserIds | NSArray<NSString *> * | nil | Directed recipient user IDs. nil or empty sends to all channel members. |
disableUpdateLastMessage | BOOL | NO | Whether to skip updating the channel's last message |
needReceipt | BOOL | NO | Whether a read receipt is required |
disableNotification | BOOL | NO | Whether to disable remote push and local notifications |
metadata | NSDictionary<NSString *, NSString *> * | nil | Message extension metadata |
pushConfig | NCPushConfig * | nil | Push notification configuration. nil uses the default strategy. |
Send a media message
Use sendMediaMessage with NCSendMediaMessageParams for image, voice, video, file, and other media types.
- Swift
- Objective-C
let imageContent = ImageMessage(imageURI: imageLocalPath)
let params = SendMediaMessageParams(content: imageContent)
channel.sendMediaMessage(
params: params,
attachedHandler: { message in
// Message persisted locally
},
progressHandler: { progress, message in
// Upload progress: 0-100
},
completionHandler: { message, error in
if let error {
print("Send failed: \(error.localizedDescription)")
} else {
print("Sent successfully: \(message?.messageId ?? "")")
}
},
cancelHandler: { message in
// Upload cancelled
}
)
NCImageMessage *imageContent = [[NCImageMessage alloc] initWithImageURI:imageLocalPath];
NCSendMediaMessageParams *params = [[NCSendMediaMessageParams alloc] initWithContent:imageContent];
[channel sendMediaMessageWithParams:params
attachedHandler:^(NCMessage *message) {
// Message persisted locally
} progressHandler:^(int progress, NCMessage *message) {
// Upload progress: 0-100
} completionHandler:^(NCMessage *message, NCError *error) {
if (error) {
NSLog(@"Send failed: %@", error.localizedDescription);
} else {
NSLog(@"Sent successfully");
}
} cancelHandler:^(NCMessage *message) {
// Upload cancelled
}];
Send a targeted message
Send a message visible only to specific users in a channel. Set directedUserIds in NCSendMessageParams:
- Swift
- Objective-C
let params = SendMessageParams(content: textContent)
params.directedUserIds = ["userId1", "userId2"]
NCSendMessageParams *params = [[NCSendMessageParams alloc] initWithContent:textContent];
params.directedUserIds = @[@"userId1", @"userId2"];
Send a mention (@) message
Set the mentionedInfo property on the message content:
- Swift
- Objective-C
let textContent = TextMessage(text: "@user1 check this")
let mentionedInfo = MentionedInfo(
type: .users,
userIdList: ["userId1"],
mentionedContent: nil
)
textContent.mentionedInfo = mentionedInfo
NCTextMessage *textContent = [[NCTextMessage alloc] initWithText:@"@user1 check this"];
NCMentionedInfo *mentionedInfo = [[NCMentionedInfo alloc]
initWithType:NCMentionedTypeUsers
userIdList:@[@"userId1"]
mentionedContent:nil];
textContent.mentionedInfo = mentionedInfo;
To mention all members:
- Swift
- Objective-C
let mentionedInfo = MentionedInfo(
type: .all,
userIdList: nil,
mentionedContent: nil
)
NCMentionedInfo *mentionedInfo = [[NCMentionedInfo alloc]
initWithType:NCMentionedTypeAll
userIdList:nil
mentionedContent:nil];
Configure push notification attributes
Set pushConfig in NCSendMessageParams to customize push behavior:
- Swift
- Objective-C
let pushConfig = PushConfig()
pushConfig.pushTitle = "Custom Title"
pushConfig.pushContent = "Custom Content"
pushConfig.iOSConfig = IOSPushConfig()
pushConfig.iOSConfig?.threadId = "groupId"
let params = SendMessageParams(content: textContent)
params.pushConfig = pushConfig
NCPushConfig *pushConfig = [[NCPushConfig alloc] init];
pushConfig.pushTitle = @"Custom Title";
pushConfig.pushContent = @"Custom Content";
pushConfig.iOSConfig = [[NCIOSPushConfig alloc] init];
pushConfig.iOSConfig.threadId = @"groupId";
NCSendMessageParams *params = [[NCSendMessageParams alloc] initWithContent:textContent];
params.pushConfig = pushConfig;
NCPushConfig properties:
| Property | Type | Description |
|---|---|---|
disablePushTitle | BOOL | Whether to hide the push notification title. Default: NO. |
pushTitle | NSString * | Push notification title. nil uses the default. |
pushContent | NSString * | Push notification content. nil uses the default. |
pushData | NSString * | Extra data attached to the push notification. |
forceShowDetailContent | BOOL | Whether to force showing notification detail content. Default: NO. |
templateId | NSString * | Push template ID for localized push content. |
iOSConfig | NCIOSPushConfig * | iOS-specific push configuration. |
androidConfig | NCAndroidPushConfig * | Android-specific push configuration. |
Send a transient message
Transient messages are not stored and are not counted toward unread totals. Ideal for typing indicators. Use a message content class with NCMessagePersistentStatus set to not persist, then send via sendMessage:
- Swift
- Objective-C
// Transient message content (for example, TypingStatusMessage or a custom non-persisted type)
let params = SendMessageParams(content: typingContent)
channel.sendMessage(params: params, attachedHandler: nil, completionHandler: nil)
// Transient message content (e.g., typing status or a custom non-persisted type)
NCSendMessageParams *params = [[NCSendMessageParams alloc] initWithContent:typingContent];
[channel sendMessageWithParams:params attachedHandler:nil completionHandler:nil];