请选择 进入手机版 | 继续访问电脑版

默认
发表评论 1
想开发IM:买成品怕坑?租第3方怕贵?找开源自已撸?尽量别走弯路了... 找站长给点建议
使用融云 IM 点击最近聊天记录时跳转到 @ 自己的消息
有没有遇到过这样的问题,在最近聊天记录列表里面有 @ 你的消息,点列表里面对应的记录,进入聊天页面以后,跳到了最新接收到的消息,想要看 @ 自己的消息,还得可劲儿的下来去找,使用体验不好,想要改善的话,往下看。
实现思路就是获取会话中 @ 自己的消息,把这条消息的时间传给聊天页面,然后再跳转,就可以跳转到这条消息了。
  • 在 push 到会话页面之前,调 RCIMClient 类下面接口,获取 @ 自己的消息

/*! 获取会话中@提醒自己的消息
@param conversationType    会话类型
@param targetId            目标会话ID
@discussion 此方法从本地获取被@提醒的消息(最多返回10条信息)
@warning 使用 IMKit 注意在进入会话页面前调用,否则在进入会话清除未读数的接口 clearMessagesUnreadStatus: targetId: 以及 设置消息接收状态接口 setMessageReceivedStatus:receivedStatus:会同步清除被提示信息状态。
*/
- (NSArray *)getUnreadMentionedMessagesRCConversationType)conversationType targetIdNSString *)targetId;
  • 遍历得到数组,找到自己想要跳转到的消息,把消息的 sentTime 传给要跳转的聊天页面,再 push 到聊天页面。

/** 进入页面时定位的消息的发送时间
@discussion 用于消息搜索之后点击进入页面等场景
*/
@property (nonatomic, assign) long long locatedMessageSentTime;
示例代码
- (void)onSelectedTableRowRCConversationModelType)conversationModelType conversationModelRCConversationModel *)model atIndexPathNSIndexPath *)indexPath {
    if (model.conversationType == ConversationType_GROUP) {
        NSArray *msgs = [[RCIMClient sharedRCIMClient] getUnreadMentionedMessages:model.conversationType targetId:model.targetId];
        if (msgs.count > 0) {
            RCMessage *msg = msgs[0];
            RCConversationViewController *vc = [[RCConversationViewController alloc] initWithConversationType:model.conversationType targetId:model.targetId];
            vc.locatedMessageSentTime = msg.sentTime;
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}
融云的官网:https://www.rongcloud.cn/
从融云的官网文档能够找到点击会话列表 cell 的回调方法,在该方法里获取 @ 自己的消息,如果有,将该消息的 sentTime 设置给聊天页面对象的 locatedMessageSentTime,再 push。
**注:示例代码中使用的聊天页面是融云 SDK 中的原始类,如果你自己继承了,就替换为你自己的类,别的就没啥了。

即时通讯网 - 即时通讯开发者社区! 来源: - 即时通讯开发者社区!

上一篇:融云 IM SDK 如何插入消息下一篇:干货分享——使用融云通讯能力库 IMLib 实现单群聊的阅读回执
推荐方案
打赏楼主 ×
使用微信打赏! 使用支付宝打赏!

返回顶部