2

我在添加朋友、发送邀请以及在群聊中遇到困难,比如使用 xmpp 为所有人发送一条消息。我知道我需要使用 XEP-0045。但我没有成功。谁能告诉我该怎么做。

  1. 发送一对一聊天的好友请求。
  2. 发送邀请加入聊天室。
  3. 向聊天室的朋友发送消息。

如果有人有示例代码会很棒..

提前致谢

4

2 回答 2

2

对于#3:向聊天室的朋友发送消息。

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

}
于 2014-07-03T12:01:49.897 回答
2

第 2 点:发送邀请加入聊天室。

当您在以下委托 (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:向聊天室的朋友发送消息。实际上,该消息是在组中广播的。一定会交付给小组中的所有成员。

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

     }
 }
于 2014-10-03T10:18:20.267 回答