同一用户所有已登录设备都可以获取该用户在所有设备上的历史消息;
用户可从服务器获取全部历史消息,也可以根据本地数据库存储的消息有选择的获取服务器历史消息;
消息漫游支持以会话为单位获取历史消息;
漫游消息的存储不限制条数和消息类型,时间限制分为3个月和6个月两种,客户可根据自身需求进行选择;
Android
try {
EMClient.getInstance().chatManager().fetchHistoryMessages(
toChatUsername, EaseCommonUtils.getConversationType(chatType), pagesize, "");
final List<EMMessage> msgs = conversation.getAllMessages();
int msgCount = msgs != null ? msgs.size() : 0;
if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
String msgId = null;
if (msgs != null && msgs.size() > 0) {
msgId = msgs.get(0).getMsgId();
}
conversation.loadMoreMsgFromDB(msgId, pagesize - msgCount);
}
messageList.refreshSelectLast();
} catch (HyphenateException e) {
e.printStackTrace();
}
iOS
- (EMCursorResult *)fetchHistoryMessagesFromServer:(NSString *)aConversationId
conversationType:(EMConversationType)aConversationType
startMessageId:(NSString *)aStartMessageId
pageSize:(int)aPageSize
error:(EMError **)pError;
- (void)asyncFetchHistoryMessagesFromServer:(NSString *)aConversationId
conversationType:(EMConversationType)aConversationType
startMessageId:(NSString *)aStartMessageId
pageSize:(int)aPageSize
complation:(void (^)(EMCursorResult *aResult, EMError *aError))aCompletionBlock;