Need a solution to implement xmpp add friends in group chat and sending message to them in once in ios

家住魔仙堡 提交于 2020-01-04 19:56:10

问题


I'm having difficulties to add friends, sending invitations and also in group chat like sending one message for all using xmpp. i know that I need to use XEP-0045. But I am not succeeded. Can anybody tell me how to do it.

  1. Send friend request for one to one chat.
  2. send invitation to join chat room.
  3. send message to chat room's friends.

if somebody has sample code that would be great..

Thanks in advance


回答1:


for #3 : send message to chat room's friends.

-(void) sendGroupMessage:(NSString *) groupJID Message:(NSString *)msg{

    XMPPJID *roomJID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",groupJID,SERVER_URL]];

    XMPPRoom *muc = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomJID
                                            dispatchQueue:dispatch_get_main_queue()];

    [muc   activate:xmppStream];

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

    [muc   sendMessageWithBody:msg];

}



回答2:


Point 2: Send invitation to join chat room.

You can send invitation to others when you get the response in following delegate (xmppRoomDidCreate):

- (void)xmppRoomDidCreate:(XMPPRoom *)xmppRoom
{
    NSLog(@"xmppRoomDidCreate");
    [xmppRoom inviteUser:[User JID Here] withMessage:@"Your Message Here"];
    // You can send invitations in loop if you have multiple users to invite
}

Point 3: Send message to chat room's friends. Actually the message is broadcasted in group. Surely shall be delivered to all members in group.

- (void) sendMessageInGroup:(NSString *) message withGroupName:(NSString *) groupName
{
    NSString * qualifiedGroupName = [NSString stringWithFormat:@"%@@%@", [groupName lowercaseString], SERVER_NAME];

    //      self.xmppRoomDetails consists of your muc rooms' objects i.i XMPPRoom
    for (int i = 0; i < self.xmppRoomDetails.count; i++)
    {

        XMPPRoom * room = [self.xmppRoomDetails objectAtIndex:i];
        XMPPJID * myRoomJID = room.myRoomJID;
        NSString * roomName = [NSString stringWithFormat:@"%@@%@", [myRoomJID.user lowercaseString], SERVER_NAME];

        if ([qualifiedGroupName rangeOfString:roomName].location != NSNotFound)
        {
            XMPPRoom * sendMessageWithRoom = [self.xmppRoomDetails objectAtIndex:i];
            [sendMessageWithRoom sendMessage:message];
        }

     }
 }


来源:https://stackoverflow.com/questions/16336755/need-a-solution-to-implement-xmpp-add-friends-in-group-chat-and-sending-message

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