Skip to main content

Custom message types

Beyond built-in message types, you can create custom message types by subclassing:

  • NCMessageContent — for regular messages (text, location, etc.) that do not involve media file uploads.
  • NCMediaMessageContent — for media messages that require upload/download handling (images, files, etc.).

Create a custom message type

Custom message types must conform to these protocols:

Encoding protocol (required)

The NCMessageCoding protocol defines message type identification, serialization/deserialization, and search keywords:

swift
import NexconnChatSDK
+ getObjectName; // Unique type identifier (avoid "RC:" prefix)
- encode; // Serialize to JSON for transmission
- (void)decodeWithData:data; // Deserialize from JSON
- (NSArray<NSString *> *)getSearchableWords; // Return nil if not searchable

Storage protocol (required)

The NCMessagePersistentCompatible protocol controls storage and unread count behavior:

swift
import NexconnChatSDK
+ (MessagePersistent)persistentFlag
FlagLocal storageServer storageCounts as unread
NCMessagePersistentNoneNoSupports missed messagesNo
NCMessagePersistentCountedYesYes (stored in history)Yes
NCMessagePersistentPersistedYesYes (stored in history)No
NCMessagePersistentStatusNoNoNo

Content summary protocol (optional)

The NCMessageContentView protocol defines how the message appears in channel lists and local notifications:

swift
import NexconnChatSDK
- conversationDigest

Register a custom message type

Register your custom type after SDK initialization and before connecting:

swift
import NexconnChatSDK
NCEngine registerCustomMessages:@[MyCustomMessage.class
tip

Unregistered types appear as RC:UnknownMsg.

Send custom messages

  • Subclasses of NCMessageContent: use sendMessage.
  • Subclasses of NCMediaMessageContent: use sendMediaMessage.

Push notifications for custom messages

Specify pushContent when sending custom messages to support push notifications. Without pushContent, the server cannot trigger push for custom types.

tip

Transient messages (NCMessagePersistentStatus) do not support push.