Xmpp IOS multiuser chat . i didnot find a way to accept the invitation from group ? how i can accept the incomming invitation

帅比萌擦擦* 提交于 2019-12-06 08:44:39

问题


When i send invitation this function is called but i can't understand what line of code should use for accept invitation*. am trying to create a multi user and multi groups invitation also called did received message function.

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

回答1:


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

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

To accept incoming invitation for 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];
}



回答2:


to accept the 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];
}



回答3:


In my case I need to use both answers and define self like

@interface XMPPDelegate : NSObject <XMPPMUCDelegate>

Activating XMPPMUC protocol as below:

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

Receive join 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];
}


来源:https://stackoverflow.com/questions/25967692/xmpp-ios-multiuser-chat-i-didnot-find-a-way-to-accept-the-invitation-from-grou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!