我正在使用Robbiehanson的iOS XMPPFramework。我正在尝试创建一个MUC房间,并邀请用户进入群聊室,但它无法正常工作。
我使用以下代码:
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应该收到邀请信息但没有任何事情发生。
任何帮助将不胜感激。 :)
答案 0 :(得分:32)
在探索各种解决方案之后,我决定在这里编译和分享我的实现:
创建XMPP会议室
XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init];
/**
* Remember to add 'conference' in your JID like this:
* e.g. 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];
检查此委托中是否已成功创建空间:
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
检查您是否已加入此代表中的会议室:
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
创建空间后,获取房间配置表单:
- (void)xmppRoomDidJoin:(XMPPRoom *)sender {
[sender fetchConfigurationForm];
}
配置您的房间
/**
* 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];
}
邀请用户
- (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!"];
}
在那里,您已经创建了一个XMPP多用户/组聊天室,并邀请了一位用户。 :)
答案 1 :(得分:1)
我觉得在alloc-init之后要做的第一件事是将它附加到你的xmppStream,所以它可以使用xmppStream来发送/接收消息。
更确切地说:
XMPPRoom *room = [[XMPPRoom alloc] initWithRoomName:@"user101@conference.jabber.org/room" nickName:@"room"];
[room activate:[self xmppStream]];
//other things (create/config/...)
答案 2 :(得分:1)
查看最新的XMPPMUCLight& XMPPRoomLight类似于Whatsapp和其他今天的趋势社交应用程序室,在线下或者没有人在室内时不会被摧毁或被踢。
请参阅此documentation& mod from MongooseIM