XMPPFramework – 如何创buildMUC房间并邀请用户?

我正在使用Robbiehanson的iOS XMPPFramework。 我正在尝试创build一个MUC房间,并邀请用户join群组聊天室,但这不起作用。

我正在使用下面的代码:

XMPPRoom *room = [[XMPPRoom alloc] initWithRoomName:@"user101@conference.jabber.org/room" nickName:@"room"]; [room createOrJoinRoom]; [room sendInstantRoomConfig]; [room setInvitedUser:@"ABC@jabber.org"]; [room activate:[self xmppStream]]; [room inviteUser:jid1 withMessage:@"hello please join."]; [room sendMessage:@"HELLO"]; 

用户ABC@jabber.org应该收到邀请信息,但没有任何事情发生。

任何帮助将不胜感激。 🙂

在探索了各种解决scheme后,我决定在这里编译和分享我的实现:

  1. 创build一个XMPP房间:

     XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init]; /** * Remember to add 'conference' in your JID like this: * eg uniqueRoomJID@conference.yourserverdomain */ XMPPJID *roomJID = [XMPPJID jidWithString:@"chat@conference.shakespeare"]; XMPPRoom *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]; 
  2. 检查此代表是否成功创build了会议室:

     - (void)xmppRoomDidCreate:(XMPPRoom *)sender 
  3. 检查你是否join了这个代表的房间:

     - (void)xmppRoomDidJoin:(XMPPRoom *)sender 
  4. 创build房间后,取房间configuration表:

     - (void)xmppRoomDidJoin:(XMPPRoom *)sender { [sender fetchConfigurationForm]; } 
  5. configuration你的房间

     /** * Necessary to prevent this message: * "This room is locked from entry until configuration is confirmed." */ - (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]; } 

    参考文献: XEP-0045:多用户聊天 , 实现群聊

  6. 邀请用户

     - (void)xmppRoomDidJoin:(XMPPRoom *)sender { /** * You can read from an array containing participants in a for-loop * and send multiple invites in the same way here */ [sender inviteUser:[XMPPJID jidWithString:@"keithoys"] withMessage:@"Greetings!"]; } 

在那里,你已经创build了一个XMPP多用户/组聊天室,并邀请了一个用户。 🙂

我有这样的感觉,alloc-init之后要做的第一件事就是将它附加到你的xmppStream,所以它可以使用xmppStream发送/接收消息。

更确切地说:

 XMPPRoom *room = [[XMPPRoom alloc] initWithRoomName:@"user101@conference.jabber.org/room" nickName:@"room"]; [room activate:[self xmppStream]]; //other things (create/config/...) 

查看最新的XMPPMUCLight&XMPPRoomLight,它类似于Whatsapp和其他今天的趋势社交应用程序的房间,不会被破坏或成员在离线或室内没有人踢。

从MongooseIM中引用这个文档和mod