在XMPP的"groupchat"中,创建群的时候会收到群发的"This room is locked from entry until configuration is confirmed."和"This room is now unlocked."警告,并且每次进群的时候都会收到"This room is not anonymous."警告,而且自己向群发的消息,每次群还会发回给我,看起来就像自己发给自己,造成消息重复。这些问题怎么解决?(问题截图如下)
实际上这些消息其他人也碰到过,群聊的时候会有各种配置项,如果不写配置,默认创建的是Instant room。群聊的时候,自己发给群一条消息,群会帮你广播给群里所有人,所以你收到自己发出的消息也是正常现象。如果你不想收到上述所有的警告,你需要修改"/XMPPFramework的/XMPPFramework/Extenstions/XEP-0136/XMPPMessageArchiving.m"这个路径的框架原文件。(红色的是修改添加的代码)。
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message { XMPPLogTrace(); XMPPJID *jid = message.from; NSString *str = jid.resource; //发给自己的消息会忽略 if ([str isEqualToString:kGlobal.userInfo.sApplyName]) { return; } //群发的警告会忽略 This room is not anonymous. if (message.childCount>=2) { DDXMLElement *element = message.children[1]; if (element.childCount>0) { DDXMLElement *subChild = element.children[0]; if (subChild.attributes.count>0) { DDXMLNode *statusNode = subChild.attributes[0]; if ([statusNode.name isEqualToString:@"code"]&&[statusNode.stringValue isEqualToString:@"100"]) { return; } } } } //忽略群发警告 This room is locked from entry until configuration is confirmed. if ([message.body isEqualToString:@"This room is locked from entry until configuration is confirmed."]) { return; } //忽略群发警告 This room is now unlocked. if ([message.body isEqualToString:@"This room is now unlocked."]) { return; } if ([self shouldArchiveMessage:message outgoing:NO xmppStream:sender]) { [xmppMessageArchivingStorage archiveMessage:message outgoing:NO xmppStream:sender]; } }
改善后的截图如下:
参考链接:
http://www.tuicool.com/articles/ZrIrIn3
http://wiki.jabbercn.org/XEP-0045#.E6.96.B0.E5.BB.BA.E4.BF.9D.E7.95.99.E6.88.BF.E9.97.B4