Page event listeners
Chat UI provides two types of listeners:
- Global
NCChatUIlisteners: Connection status, network status, message policies, message events, and send interception. - Page-level listeners: Various callbacks for the channel list page and channel page.
Global listeners
Monitor connection status
Objective C
[[NCChatUI shared] addConnectionStatusDelegate:self];
[[NCChatUI shared] removeConnectionStatusDelegate:self];
- (void)onNCChatUIConnectionStatusChanged:(NCConnectionStatus)status {
// Handle connection status changes
}
Notification
Chat UI also dispatches NCChatUIDispatchConnectionStatusChangedNotification, where the object is an NSNumber corresponding to NCConnectionStatus.
Monitor network status
Objective C
@interface AppDelegate () <NCChatUINetworkStatusDelegate>
@end
- (void)setupNetworkDelegate {
[[NCChatUI shared] addNetworkStatusDelegate:self];
}
- (void)onNCChatUINetworkStatusChanged:(NCChatUINetworkStatus)status {
// status: No network / WiFi / Cellular
}
Message policies
To control whether a message appears in the UI, plays an alert sound, or triggers a local notification, implement NCChatUIMessagePolicyDelegate:
Objective C
@interface AppDelegate () <NCChatUIMessagePolicyDelegate>
@end
- (void)setupMessagePolicy {
[NCChatUI shared].messagePolicyDelegate = self;
}
- (BOOL)shouldInterceptMessage:(NCMessage *)message {
return NO;
}
- (BOOL)shouldSuppressAlertSoundForMessage:(NCMessage *)message {
return NO;
}
- (BOOL)shouldSuppressLocalNotificationForMessage:(NCMessage *)message
senderName:(NSString *)senderName {
return NO;
}
Message event listeners
Use NCChatUIMessageEventObserver to listen for global message receive and delete events.
Objective C
@interface AppDelegate () <NCChatUIMessageEventObserver>
@end
- (void)setupMessageObserver {
[[NCChatUI shared] addMessageEventObserver:self];
}
- (void)onReceivedMessage:(NCMessage *)message left:(int)left offline:(BOOL)offline {
// Message received
}
- (void)onDeletedMessagesForAll:(NSArray<NCMessage *> *)messages {
// Messages deleted globally
}
Send interception
To modify content before sending, intercept sends, or integrate with custom file upload logic, implement NCChatUIMessageInterceptor:
Objective C
@interface AppDelegate () <NCChatUIMessageInterceptor>
@end
- (void)setupMessageInterceptor {
[NCChatUI shared].messageInterceptor = self;
}
- (BOOL)interceptWillSendMessageWithParams:(NCChatUISendMessageParams *)params {
return NO;
}
- (BOOL)interceptWillSendMediaMessageWithParams:(NCChatUISendMediaMessageParams *)params {
return NO;
}
- (void)interceptDidSendMessage:(NCMessage *)message {
}
Channel list page events
NCChannelListViewController provides these common entry points:
Before displaying channel cell
Objective C
- (void)willDisplayConversationTableCell:(NCChannelListBaseCell *)cell
atIndexPath:(NSIndexPath *)indexPath;
Channel cell tap
Objective C
- (void)onSelectedTableRow:(NCChannelModelType)conversationModelType
conversationModel:(NCChannelModel *)model
atIndexPath:(NSIndexPath *)indexPath;
Avatar tap and long press
Objective C
- (void)didTapCellPortrait:(NCChannelModel *)model;
- (void)didLongPressCellPortrait:(NCChannelModel *)model;
Delete channel
Objective C
- (void)didDeleteConversationCell:(NCChannelModel *)model;
Before loading data source
Objective C
- (NSMutableArray<NCChannelModel *> *)willReloadTableData:(NSMutableArray<NCChannelModel *> *)dataSource;
Unread count update
Objective C
- (void)notifyUpdateUnreadMessageCount;
Channel page events
NCChannelViewController exposes these common callbacks.
Input box content change
Objective C
- (void)inputTextView:(UITextView *)inputTextView
shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text;
Input area height change
Objective C
- (void)chatInputBar:(NCChatSessionInputBarControl *)chatInputBar
shouldChangeFrame:(CGRect)frame;
Before and after sending
Objective C
- (NCMessageContent *)willSendMessage:(NCMessageContent *)messageContent;
- (void)didSendMessageModel:(NSInteger)status model:(NCMessageModel *)messageModel;
- (void)didCancelMessage:(NCMessageContent *)messageContent;
Before inserting and displaying messages
Objective C
- (NCMessage *)willAppendAndDisplayMessage:(NCMessage *)message;
- (void)willDisplayMessageCell:(NCMessageBaseCell *)cell atIndexPath:(NSIndexPath *)indexPath;
Plugin panel tap
Objective C
- (void)pluginBoardView:(NCPluginBoardView *)pluginBoardView
clickedItemWithTag:(NSInteger)tag;