我正在创建群聊应用。我可以使用以下代码创建组。
_xmppRoomStorage = [[XMPPRoomCoreDataStorage alloc]init];
XMPPJID *roomJID = [XMPPJID jidWithString:@"room1@conference.abc.biz"];
_xmppRoom =[[XMPPRoom alloc] initWithRoomStorage:_xmppRoomStorage jid:roomJID];
[_xmppRoom activate:_xmppStream];
[_xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
xmppRoom joinRoomUsingNickname:_userNameEdit.text history:nil];
但现在我需要向这个群组添加一些用户。任何人都可以告诉我如何向这个群组添加或邀请多个用户。
我还有一个问题。第一组活动时无法创建第二个房间。当我尝试创建第二个房间时,它会给出以下错误
“XMPPRoom [room2@conference.abc.biz] - 在创建/加入/加入时无法创建/加入会议室”
感谢。 瓦斯
答案 0 :(得分:2)
我通过以下方式解决了这个问题:
首先创建房间
-(void) CreateRoom
{
XMPPJID *roomRealJid = [XMPPJID jidWithString:jidRoom];// Room name ex. abc@conference.xyz.biz
XMPPRoom *newXmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[[self appDelegate] xmppRoomStorage] jid:roomRealJid dispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
[newXmppRoom activate: [[self appDelegate] xmppStream]];
[newXmppRoom fetchConfigurationForm];
[newXmppRoom addDelegate:[self appDelegate] delegateQueue:dispatch_get_main_queue()];
[newXmppRoom joinRoomUsingNickname:nickName history:nil password:[[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyPassword]];
}
发送邀请
// Once the room created, we get some responses from server.
// One of them is "didFetchModeratorsList".
- (void)xmppRoom:(XMPPRoom *)sender didFetchModeratorsList:(NSArray *)items
{
DDLogInfo(@"%@: %@ --- %@", THIS_FILE, THIS_METHOD, sender.roomJID.bare);
if (check the flag for room create and invite) // This has to be done only when we intended
{
NSArray* users = list of users we need to invite.
if (users.count > 0)
{
for (int i=0; i< users.count; i++)
{
NSString *jid = [NSString stringWithFormat:@"%@@xyz.biz", [users objectAtIndex:i]];
XMPPJID *xmppJID=[XMPPJID jidWithString:jid];
[sender inviteUser:xmppJID withMessage:@"Join Group."];
}
[sender sendMessageWithBody:@"Hi All"];
}
}
}
希望这有帮助。