简体   繁体   中英

Adding user to xmpp room

Hello I know there is alot question regarding this but still i could not figure out what can be the problem. I have sucessfully created group using following code.

- (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];

}

And For adding user i used following code. I have called this function with delay of 5s so room can be created succesfully before adding users.

- (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()];


}

What i am doing wrong couldnt find.

Creating and Joining (Already Created Room or Accepting Invitation To Join Room) Rooms are two differnet scenarios.

// CONFERENCE_ROOM_SERVER is the domain name for MUC

For Creating Group Do This Way:

- (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];

}

You will get the response after the group has been created successfully in this delegate:

- (void)xmppRoomDidCreate:(XMPPRoom *)sender

Now Invite Users Here This Way:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM