将用户添加到xmpp会议室

时间:2013-12-04 08:27:11

标签: ios xmpp

您好我知道有很多关于此的问题,但我仍然无法弄清楚可能是什么问题。我使用以下代码成功创建了组。

- (void)createGroup
{

iXmppEngine.userID = @"lahore123@hassan.local";
    iXmppEngine.userPass = @"password123";
    self.rosterstorage  =[[XMPPRoomCoreDataStorage alloc] init];

    XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self.rosterstorage jid:[XMPPJID jidWithString:@"test@conference.hassan.local"] dispatchQueue:dispatch_get_main_queue()];


    [xmppRoom activate:[[self iXmppEngine]xmppStream]];

    [xmppRoom joinRoomUsingNickname:@"Dev iphone" history:nil];



    [[[self iXmppEngine] xmppStream]  addDelegate:self delegateQueue:dispatch_get_main_queue()];

    [xmppRoom addDelegate:self  delegateQueue:dispatch_get_main_queue()];

    [self performSelector:@selector(joinRoom) withObject:nil afterDelay:4];

}

对于添加用户,我使用了以下代码。我已经将此函数调用了5秒,因此可以在添加用户之前成功创建空间。

- (void)joinRoom
{
    self.iXmppEngine.userID = @"lahore@hassan.local";

//    self.rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];
    XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self.rosterstorage jid:[XMPPJID jidWithString:@"test@conference.hassan.local"] dispatchQueue:dispatch_get_main_queue()];
    [xmppRoom activate:[[self iXmppEngine] xmppStream]];
    [xmppRoom joinRoomUsingNickname:@"lahore" history:nil];
    [xmppRoom fetchConfigurationForm];
    [xmppRoom configureRoomUsingOptions:nil];
    [xmppRoom addDelegate:[self iXmppEngine] delegateQueue:dispatch_get_main_queue()];


}

我做错了什么都找不到。

1 个答案:

答案 0 :(得分:0)

创建和加入(已经创建的房间或接受加入会议室的邀请)房间是两个不同的场景。

// CONFERENCE_ROOM_SERVER是MUC的域名

创建组这样做:

- (void)createChatRoom:(NSString *) newRoomName
{
    XMPPJID *roomJID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@", newRoomName, CONFERENCE_ROOM_SERVER]];

    XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];

    xmppRoom = [[XMPPRoom alloc]
                initWithRoomStorage:roomMemoryStorage
                jid:roomJID
                dispatchQueue:dispatch_get_main_queue()];

    [xmppRoom activate:[self xmppStream]];
    [xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [xmppRoom joinRoomUsingNickname:@"Your Nick Name" history:nil];

}

在此委托中成功创建组后,您将收到响应:

- (void)xmppRoomDidCreate:(XMPPRoom *)sender

现在以这种方式邀请用户:

[sender inviteUser:[XMPPJID jidWithString:inviteUserJID] withMessage:@"Any Message"];