在 iOS 中使用 XMPP 群聊。我可以使用以下代码成功创建一个组
NSString *groupName=[NSString stringWithFormat:@"%@@conference.myserver.com",self.groupNameTxtFld.text];
XMPPJID *roomJID = [XMPPJID jidWithString:groupName];
self.xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[[self xmppSharedManager] roomStorage]
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[self.xmppRoom activate:[self xmppSharedManager].xmppStream];
[self.xmppRoom addDelegate:self
delegateQueue:dispatch_get_main_queue()];
[self.xmppRoom joinRoomUsingNickname:[self xmppSharedManager].xmppStream.myJID.user
history:nil
password:nil];
创建组后进行配置。
- (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];
}
通过发送以下请求获取组
XMPPJID *servrJID = [XMPPJID jidWithString:@"conference.myserver.com"];
XMPPIQ *iq = [XMPPIQ iqWithType:@"get" to:servrJID];
[iq addAttributeWithName:@"from" stringValue:[[[[self xmppSharedManager] xmppStream] myJID] full]];
NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[[[self xmppSharedManager] xmppStream] sendElement:iq];
我面临的问题是,新创建的组可以在不发送邀请的情况下看到我的所有名册。我需要在接受团体请求时向团体展示。请建议我在哪里做错了