iOS XMPPFramework – 房间/聊天消息的历史

我正在使用XMPPFramework开发聊天应用程序

join现有房间后,如何收到留言logging?

现在我join到这样的房间:

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]; 

另外我从文档中读取示例

根据这个例子,我也尝试通过这种方式来连接空间:

 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]; 

我成功地join了房间,但没有收到以前消息的历史logging。

顺便说一句,如果在房间里至less有一个用户,我收到所有以前的消息,即使我join像下面这样的房间:

 [xmppRoom joinRoomUsingNickname:user.deviceUUID history:nil]; 

如果所有用户都离开房间,然后再次join – 历史logging为空=(

我究竟做错了什么? 我是否需要打开服务器端的一些设置来保存历史logging(例如,日志logging)?

还有一些关于文档示例的问题:

什么意思是从“参数”? 这是否意味着我只从用户bob那里询问这个房间的消息历史? 而如果我想接收所有的历史(来自任何用户的消息)呢?

什么意思是“ID”参数? 我没有在文档中find任何描述。

当你创build了一个房间,并且你已经join,你需要configuration这个房间来坚持 ,这意味着什么:

持久性房间如果最后一名乘客退出,则房间不会被毁坏; 反义词:临时室。 (你想要这个房间的configuration)。

临时房间如果最后一名乘客离开房间,则该房间被毁坏; 反义词:持久的房间。

所以,你创build并join一个房间。

 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]; [xmppRoom joinRoomUsingNickname:user.deviceUUID history:history]; 

然后,委托方法xmppRoomDidJoin:sender; 被称为(只有如果所有的权利),你必须configuration你的房间

 -(void)xmppRoomDidJoin:(XMPPRoom *)sender { NSLog("I did join."); [sender fetchConfigurationForm]; } 

fetchConfigurationForm方法发送IQ来请求初始房间configuration表单。

已发送到XMPP服务器的IQ示例:

 <iq from='crone1@shakespeare.lit/desktop' id='create1' to='coven@chat.shakespeare.lit' type='get'> <query xmlns='http://jabber.org/protocol/muc#owner'/> </iq> 

3.当XMPP服务器回答房间configuration时, -xmppRoom:sender didFetchConfigurationForm:configForm; 方法被调用。 这里是你改变房间的默认值,以使持久性,房间名称,会员只有等。

例:

 -(void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm { NSXMLElement *newConfig = [configForm copy]; NSArray *fields = [newConfig elementsForName:@"field"]; for (NSXMLElement *field in fields) { NSString *var = [field attributeStringValueForName:@"var"]; // Make Room Persistent if ([var isEqualToString:@"muc#roomconfig_persistentroom"]) { [field removeChildAtIndex:0]; [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]]; } } [sender configureRoomUsingOptions:newConfig]; } 

感谢@Moral的解释。 但就我而言,解决scheme非常简单。

ejabberd.yml的聊天服务器中,在模块mucconfiguration中添加了默认选项:

 mod_muc: ## host: "conference.HOST" db_type: odbc access: muc access_create: muc_create access_persistent: muc_create access_admin: muc_admin min_message_interval: 1.0 min_presence_interval: 5.0 default_room_options: logging: true persistent: true 

而在应用程序join室这样:

 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]; 

而已!