我正在使用可用于git的Robby Hanson的XMPP库,并且我正在尝试实施MUC或群组聊天室。如何使用iOS XMPP获取MUC房间的会员列表与会员Robbie Hanson图书馆
我正在创建使用一个用户的房间,然后尝试加入,而不邀请其他用户。问题是,如果我尝试与其他用户连接,而不是房间的创造者,我得到的错误:
<iq xmlns="jabber:client" type="error" id="A7F05488-4A84-4EC0-8A6C-0F1541690534" from="[email protected]" to="[email protected]/abdbd1bc"><query xmlns="http://jabber.org/protocol/muc#admin"><item affiliation="member"/></query><error code="403" type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
而且我搜索了错误,我发现错误403,可能会发生,如果用户被禁止。这里不是这种情况。 因此,当我尝试获取fetchConfigurationForm或fetchMembersList等房间信息时发生错误。
所以,这里是我使用的代码:
- (void)testGroupButtonFunction{
XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPJID *roomJID = [XMPPJID jidWithString:@"[email protected]"];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[self appDelegate].xmppStream];
[xmppRoom addDelegate:self
delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:[self appDelegate].xmppStream.myJID.user
history:nil
password:nil];
}
- (void)handleDidJoinRoom:(XMPPRoom *)room withNickname:(NSString *)nickname{
NSLog(@"handleDidJoinRoom");
}
- (void)handleIncomingMessage:(XMPPMessage *)message room:(XMPPRoom *)room{
NSLog(@"Incomming message: %@", message.debugDescription);
}
- (void)handleOutgoingMessage:(XMPPMessage *)message room:(XMPPRoom *)room{
NSLog(@"Outgoing message: %@", message.debugDescription);
}
- (void)xmppRoom:(XMPPRoom *)sender didFetchMembersList:(NSArray *)items{
NSLog(@"didFetchMembersList: %@", items.debugDescription);
}
- (void)xmppRoom:(XMPPRoom *)sender didNotFetchMembersList:(XMPPIQ *)iqError{
NSLog(@"didNotFetchMembersList error: %@", iqError.debugDescription);
}
- (void)xmppRoomDidCreate:(XMPPRoom *)sender{
NSLog(@"xmppRoomDidCreate");
}
- (void)xmppRoom:(XMPPRoom *)sender didConfigure:(XMPPIQ *)iqResult{
NSLog(@"didConfigure: %@", iqResult.debugDescription);
}
- (void)xmppRoomDidJoin:(XMPPRoom *)sender {
NSLog(@"xmppRoomDidJoin");
// I use the same code to create or join a room that's why I commented the next line
// [xmppRoom fetchConfigurationForm];
//Next line generates the error:
[xmppRoom fetchMembersList];
}
- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm{
NSLog(@"didFetchConfigurationForm");
NSXMLElement *newConfig = [configForm copy];
NSArray *fields = [newConfig elementsForName:@"field"];
for (NSXMLElement *field in fields)
{
NSString *var = [field attributeStringValueForName:@"var"];
NSLog(@"didFetchConfigurationForm: %@", var);
// Make Room Persistent
if ([var isEqualToString:@"muc#roomconfig_persistentroom"]) {
[field removeChildAtIndex:0];
[field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
}
if ([var isEqualToString:@"muc#roomconfig_roomdesc"]) {
[field removeChildAtIndex:0];
[field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"Apple"]];
}
}
[sender configureRoomUsingOptions:newConfig];
}
- (void)xmppRoom:(XMPPRoom *)sender didNotConfigure:(XMPPIQ *)iqResult{
NSLog(@"didNotConfigure: %@",iqResult.debugDescription);
}
我使用相同的代码来创建或加入一个房间,这就是为什么我评论的下一行:
[xmppRoom fetchConfigurationForm];
我还想补充一点,我设置了:
公共房间:1 主持人:0 membersOnly:0 canInvite:1个 roomPassword:无 canRegister:1 canDiscoverJID:1 logEnabled:1
另外,如果我尝试从一个设备发送消息,当我检索记录与另一个的第二设备上的消息用户(该用户不是组的创建者/管理员)我使用LOG_LEVEL_VERBOSE在控制台中看到传入消息,但它不调用委托方法。 任何想法为什么不调用委托方法? (并且我在.h中添加了XMPPRoomDelegate) 任何人都可以帮我解决这个错误吗? 非常感谢您的耐心和支持!