XMPp IOS multiplayer chat. I haven't found a way to accept an invitation from a group? how can i accept the invitation

When I send an invitation, this function gets called, but I can't figure out which line of code should be used to accept the invitation *. I am trying to create a multi user and multi group invitation the callee received the received message function.

- (void)xmppMUC:(XMPPMUC *) sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message 
{ 
}

      

+3


source to share


3 answers


accept incoming invitation:



- (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message
{ XMPPRoom *mu = [[XMPPRoom alloc] initWithRoomStorage:xmpproomMstorage jid:roomJID
                                           dispatchQueue:dispatch_get_main_queue()];

    [mu   activate:xmppStream];
    [mu   addDelegate:self delegateQueue:dispatch_get_main_queue()];

    self.toSomeOne = roomJID;

    [mu activate: self.xmppStream];
    [mu fetchConfigurationForm];
    [mu addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [mu joinRoomUsingNickname:xmppStream.YourJid.user history:nil password:@"Your Password"];
self.toSomeOne = roomJID;
    XMPPPresence *presence = [XMPPPresence presence];
   [[self xmppStream] sendElement:presence];
    [xmppRoster addUser:roomJID  withNickname:roomJID.full];
    [self goOnline];
}

      

+2


source


This is how you can accept a group invitation. You just need to activate the XMPPMUC protocol as shown below:

XMPPMUC * xmppMUC = [[XMPPMUC alloc] initWithDispatchQueue:dispatch_get_main_queue()];
[xmppMUC   activate:_xmppStream];
[xmppMUC addDelegate:self delegateQueue:dispatch_get_main_queue()];

      



To accept an invitation for a MUC:

- (void)xmppMUC:(XMPPMUC *)sender didReceiveRoomInvitation:(XMPPMessage *)message
{
    NSXMLElement * x = [message elementForName:@"x" xmlns:XMPPMUCUserNamespace];
    NSXMLElement * invite  = [x elementForName:@"invite"];
    if (!isEmpty(invite))
    {
        NSString * conferenceRoomJID = [[message attributeForName:@"from"] stringValue];
        [self joinMultiUserChatRoom:conferenceRoomJID];

    }
}

- (void) joinMultiUserChatRoom:(NSString *) newRoomName
{
    XMPPJID *roomJID = [XMPPJID jidWithString:newRoomName];
    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 NICKNAME" history:nil];
}

      

+4


source


In my case, I need to use both answers and define myself as

@interface XMPPDelegate : NSObject <XMPPMUCDelegate>

      

XMPPMUC protocol activation as shown below:

XMPPMUC * xmppMUC = [[XMPPMUC alloc] 
initWithDispatchQueue:dispatch_get_main_queue()];
[xmppMUC   activate:_xmppStream];
[xmppMUC addDelegate:self delegateQueue:dispatch_get_main_queue()];

      

Get connection message:

- (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message
{
    DDLogDebug(@"%@", message);
    XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
    XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemoryStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
    [xmppRoom activate:xmppStream];
    [xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [xmppRoom joinRoomUsingNickname: xmppStream.myJID.user history:nil password:password];
    XMPPPresence *presence = [XMPPPresence presence];
    [[self xmppStream] sendElement:presence];
    [xmppRoster addUser:roomJID  withNickname:roomJID.full];
    [self goOnline];
}

      

0


source







All Articles