Read receipts
Read receipts track per-message read status. Supported in direct and group channels.
Send a message with read receipt
Set needReceipt in message send params before sending:
- Swift
- Objective-C
swift
import NexconnChatSDK
let params = SendMessageParams(content: content)
params.needReceipt = true
guard let channel = GroupChannel(channelId: "groupId") else { return }
channel.sendMessage(params: params, attachedHandler: nil, completionHandler: nil)
Objective C
NCSendMessageParams *params = [[NCSendMessageParams alloc] initWithContent:content];
params.needReceipt = YES;
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel sendMessageWithParams:params attachedHandler:nil completionHandler:nil];
| Property | Type | Description |
|---|---|---|
needReceipt (on NCSendMessageParams) | BOOL | Whether the recipient should send a read receipt |
needReceipt (on NCMessage) | BOOL | Read-only property indicating whether a receipt is required for this message |
sentReceipt (on NCMessage) | BOOL | Whether the read receipt has been sent |
Send a read receipt
After the recipient reads a message, send a read receipt by calling sendReadReceiptResponse on the channel instance:
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = GroupChannel(channelId: "groupId") else { return }
channel.sendReadReceiptResponse(messageIds: [message.messageId]) { error in
if error == nil {
// Receipt sent
}
}
Objective C
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel sendReadReceiptResponseWithMessageIds:@[message.messageId]
completion:^(NCError *error) {
if (!error) {
// Receipt sent
}
}];
Listen for read receipts
Register an NCMessageHandler and implement onMessageReceiptResponse::
- Swift
- Objective-C
swift
import NexconnChatSDK
final class MyMessageHandler: NSObject, MessageHandler {
func onMessageReceiptResponse(_ event: MessageReceiptResponseEvent) {
for response in event.responses {
// response.messageId: server message ID
// response.channelIdentifier: channel where the receipt was sent
// response.readCount: number of users who have read the message
// response.unreadCount: number of users who have not read it yet
// response.totalCount: total recipient count
// response.users: list of MessageReadReceiptUser (userId, timestamp, isMentioned)
print("Message \(response.messageId) read by \(response.readCount) users")
}
}
}
let handler = MyMessageHandler()
NCEngine.addMessageHandler(identifier: "MyHandler", handler: handler)
Objective C
[NCEngine addMessageHandlerWithIdentifier:@"MyHandler" handler:self];
- (void)onMessageReceiptResponse:(NCMessageReceiptResponseEvent *)event {
for (NCMessageReadReceiptResponse *response in event.responses) {
// response.messageId: server message ID
// response.channelIdentifier: channel where the receipt was sent
// response.readCount: number of users who have read the message
// response.unreadCount: number of users who have not read it yet
// response.totalCount: total recipient count
// response.users: list of NCMessageReadReceiptUser (userId, timestamp, isMentioned)
NSLog(@"Message %@ read by %ld users", response.messageId, (long)response.readCount);
}
}