【发布时间】:2015-04-08 08:10:16
【问题描述】:
我正在使用XMPPFramework开发聊天应用程序
加入现有房间后如何接收消息历史记录?
现在我像这样加入房间:
XMPPJID *roomJid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",systemName,xmppServer]];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[XMPPRoomHybridStorage sharedInstance] jid:roomJid];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"100"];
[xmppRoom joinRoomUsingNickname:user.deviceUUID history:history];
我还阅读了来自documentation的示例
根据这个例子,我也尝试以这种方式加入房间:
XMPPJID *roomJid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",systemName,xmppServer]];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[XMPPRoomHybridStorage sharedInstance] jid:roomJid];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
[presence addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"bob@%@",xmppServer]];
[presence addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@@conference.%@/%@",systemName,xmppServer,user.deviceUUID]];
NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:@"http://jabber.org/protocol/muc"];
NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"100"];
[x addChild:history];
[presence addChild:x];
[xmppRoom joinRoomUsingNickname:user.deviceUUID history:presence];
我成功加入房间,但没有收到以前的消息历史记录。
顺便说一句,如果房间里至少有一个用户,我会收到 所有 以前的消息,即使我加入房间,例如:
[xmppRoom joinRoomUsingNickname:user.deviceUUID history:nil];
如果所有用户都离开了房间,然后又有一些用户再次加入 - 历史为空=(
我做错了什么? 我是否需要打开服务器端的某些设置来保存历史记录(例如,日志记录)?
还有一些关于文档示例的问题:
什么是“from”参数?这是否意味着我只向用户 bob 询问此房间中的消息历史记录?如果我想接收所有历史记录(来自任何用户的消息)怎么办?
什么是“id”参数?我在文档中没有找到任何描述。
【问题讨论】:
标签: ios xmpp xmppframework