逐条消息已读功能
重要提示
逐条消息已读功能(消息已读 V5)支持逐条设置接收消息的已读状态,支持单聊和群聊会话类型。
发送消息
若需支持已读回执,发送消息时需要在 RCMessage 中将 needReceipt 设置为 YES。
Objective C
RCMessage *message = ...;
message.needReceipt = YES;
[[RCCoreClient sharedCoreClient] sendMessage:message
pushContent:nil
pushData:nil
attached:^(RCMessage * _Nullable message) {
// message save into db.
} successBlock:^(RCMessage * _Nonnull successMessage) {
// message send success.
} errorBlock:^(RCErrorCode nErrorCode, RCMessage * _Nonnull errorMessage) {
// message send failed.
}];
消息对象新增属性
| 参数 | 类型 | 说明 |
|---|---|---|
| needReceipt | BOOL | 是否支持发送已读回执 |
| sentReceipt | BOOL | 是否已经发送已读回执 |
发送已读回执
消息接收方在阅读过某条消息后,需要主动发送已读回执给发送方。调用sendReadReceiptResponseV5:messageUIds:completion:方法,需要传入会话标识(identifier)和消息唯一 ID。可以传入指定消息的发送时间(messageUIds)。
| 参数 | 类型 | 说明 |
|---|---|---|
| identifier | RCConversationIdentifier | 消息所属的会话标识 |
| messageUIds | NSArray | 发送已读回执的消息数组 |
| completion | Block | 结果回调 |
Objective C
RCConversationIdentifier *identifier = [[RCConversationIdentifier alloc] init];
identifier.type = ConversationType_GROUP;
identifier.targetId = @"tId";
[[RCCoreClient sharedCoreClient] sendReadReceiptResponseV5:identifier
messageUIds:@[@"MessageUID"]
completion:^(RCErrorCode code) {
// send result.
}];
接 收已读回执回调
消息接收方发送已读回执后,消息发送方会收到有人发送已读回执的回调。开发者可以注册已读回执监听 addReadReceiptV5Delegate,实现 didReceiveMessageReadReceiptResponses 方法,接收已读回执信息。
| 参数 | 类型 | 说明 |
|---|---|---|
| responses | NSArray | 消息已读回执的响应信息 RCReadReceiptResponseV5 数组 |
Objective C
// 添加已读回执监听。
[[RCCoreClient sharedCoreClient] addReadReceiptV5Delegate:self];
// 在监听回调中处理已读回执信息。
- (void)didReceiveMessageReadReceiptResponses:(NSArray<RCReadReceiptResponseV5 *> *)responses {
// receive responses.
}