【问题标题】:Xmpp IOS multiuser chat . i didnot find a way to accept the invitation from group ? how i can accept the incomming invitationXmpp IOS 多用户聊天。我没有找到接受群邀请的方法?我怎样才能接受进来的邀请
【发布时间】:2014-11-16 01:00:37
【问题描述】:

我发送邀请时调用此函数,但我不明白应该使用哪一行代码接受邀请*。我也在尝试创建多用户和多组邀请 调用确实收到消息函数。

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

【问题讨论】:

  • 我的聊天室和聊天工作正常我在我的应用程序中测试了一个用户,在 imessages 上测试了一个 xmpp 本地用户..两者都可以在群组邀请中聊天。

标签: ios xmpp chatroom invitation muc


【解决方案1】:

这是您接受群组邀请的方式。您只需要激活您的 XMPPMUC 协议,如下所示:

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

要接受收到的 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];
}

【讨论】:

  • 现在最新的委托方法是:-(void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *)roomJID didReceiveInvitation:(XMPPMessage *)message 。在- (void)xmppMUC:(XMPPMUC *)sender didReceiveRoomInvitation:(XMPPMessage *)message 上卡了几天。
  • 可以分享一下演示链接吗?
  • 这是 MUC 组吗?每次用户上线都要加入这个群吗?
  • @Fatima Arshad 你能帮我吗stackoverflow.com/questions/38895012/…
【解决方案2】:

接受传入的邀请:

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

【讨论】:

  • 你好@shahbaz,这里的 self.toSomeone 是什么?
  • @Sushil ,当其他人邀请您加入任何房间时调用此方法 - (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message {} 。和 self.toSomeOne = roomJID; .我们必须返回接受或拒绝。为此,我们需要recipent的jid(就像使用电话号码回复或发送消息一样) self.toSomeOne = roomJID;在这一行中,我们只设置接收者 ID,然后在代码中发送接受或拒绝。希望你能理解,否则再问。
  • 谢谢@shahbaz,我怎么知道用户是否接受了请求?我无法从核心数据加载数据。就像我们在对等聊天中所做的那样,我们可以从 coredata 中检索整个聊天。但是,在 MUC 中,我们如何从核心数据中保存和检索数据?
  • 可以分享一下演示链接吗?
【解决方案3】:

在我的情况下,我需要同时使用两个答案并定义 self

@interface XMPPDelegate : NSObject <XMPPMUCDelegate>

激活XMPPMUC协议如下:

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

接收加入消息:

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

【讨论】:

  • 可以分享一下演示链接吗?
猜你喜欢
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多