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
- Objective-C
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
+ (NSString *)getObjectName; // Unique type identifier (avoid "RC:" prefix)
- (NSData *)encode; // Serialize to JSON for transmission
- (void)decodeWithData:(NSData *)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
- Objective-C
import NexconnChatSDK
+ (MessagePersistent)persistentFlag
+ (NCMessagePersistent)persistentFlag;
| Flag | Local storage | Server storage | Counts as unread |
|---|---|---|---|
NCMessagePersistentNone | No | Supports missed messages | No |
NCMessagePersistentCounted | Yes | Yes (stored in history) | Yes |
NCMessagePersistentPersisted | Yes | Yes (stored in history) | No |
NCMessagePersistentStatus | No | No | No |
Content summary protocol (optional)
The NCMessageContentView protocol defines how the message appears in channel lists and local notifications:
- Swift
- Objective-C
import NexconnChatSDK
- conversationDigest
- (NSString *)conversationDigest;
Register a custom message type
Register your custom type after SDK initialization and before connecting:
- Swift
- Objective-C
import NexconnChatSDK
NCEngine registerCustomMessages:@[MyCustomMessage.class
[NCEngine registerCustomMessages:@[MyCustomMessage.class]];
Unregistered types appear as RC:UnknownMsg.
Send custom messages
- Subclasses of
NCMessageContent: usesendMessage. - Subclasses of
NCMediaMessageContent: usesendMediaMessage.
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.
Transient messages (NCMessagePersistentStatus) do not support push.