Typing indicator
The typing indicator lets users see when someone else is composing a message in a channel. Direct channels support sending typing status; other channel types use the channel event handler to observe incoming typing events.
Send typing status
Call sendTypingStatusWithTypingMessageType: on an NCDirectChannel instance to broadcast the current user's typing state:
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.sendTypingStatus(typingMessageType: MessageType.text)
Objective C
NCDirectChannel *channel = [[NCDirectChannel alloc] initWithChannelId:@"targetUserId"];
[channel sendTypingStatusWithTypingMessageType:[NCMessageType text]];
| Parameter | Type | Description |
|---|---|---|
typingMessageType | NSString * | The message type being typed. Pass a value from NCMessageType, e.g., NCMessageType.text. |
tip
Call this method each time the user's input changes. The server automatically expires the typing state after a short interval if no update is sent.
Listen for typing status changes
Register an NCChannelHandler to receive typing status notifications from other users:
- Swift
- Objective-C
swift
import NexconnChatSDK
final class MyChannelHandler: NSObject, ChannelHandler {}
let channelHandler = MyChannelHandler()
NCEngine.addChannelHandler(identifier: "MyChannelHandler", handler: channelHandler)
Objective C
[NCEngine addChannelHandlerWithIdentifier:@"MyChannelHandler" handler:self];
Implement the NCChannelHandler protocol method:
- Swift
- Objective-C
swift
import NexconnChatSDK
func onTypingStatusChanged(_ event: TypingStatusChangedEvent) {
for info in event.userTypingStatus {
print("User \(info.userId) is typing in channel \(event.channelIdentifier.channelId)")
}
}
Objective C
- (void)onTypingStatusChanged:(NCTypingStatusChangedEvent *)event {
for (NCChannelUserTypingStatusInfo *info in event.userTypingStatus) {
NSLog(@"User %@ is typing in channel %@", info.userId, event.channelIdentifier.channelId);
}
}
NCChannelUserTypingStatusInfo properties:
| Property | Type | Description |
|---|---|---|
userId | NSString * | ID of the user who is typing. |
typingMessageType | NSString * | Message type being typed. |
sentTime | int64_t | Typing status message sent time in milliseconds. |