如何使用xmppframework创建一个新的聊天群组?

3

大家好,我正在开发一款IOS聊天应用程序,已经完成了一对一聊天,但在搜索关于群聊的信息后,没有找到如何在xmppframework中创建普通群组的方法。

我已经尝试了以下链接:

iOS XMPP群聊实现

接受聊天室邀请

如何在iPhone中使用XMPPFramework创建多用户聊天室

XMPPFramework - 如何创建多用户聊天室?

但是这些链接都没有给出积极的回应。

在编码方面,我尝试了:

XMPPRoomCoreDataStorage *rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];
    XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:@"test@conference.domainName.com/rohit"] dispatchQueue:dispatch_get_main_queue()];
    [xmppRoom configureRoomUsingOptions:nil];
    [xmppRoom activate:[self xmppStream]];
    [xmppRoom addDelegate:self
            delegateQueue:dispatch_get_main_queue()];
    [xmppRoom inviteUser:[XMPPJID jidWithString:@"abc@domainName.com"] withMessage:@"Hi join room"];

Also this

- (void)createOrEnterRoom:(NSString *)roomName
{
    //here we enter a room, or if the room does not yet exist, this method creates it
    //per XMPP documentation: "If the room does not yet exist, the service SHOULD create the room"
    //this method accepts an argument which is what you would baptize the room you wish created
    XMPPPresence *presence = [XMPPPresence presence];
    NSString *room = [roomName stringByAppendingString:@"@conference.domain.com"];
    [presence addAttributeWithName:@"to" stringValue:room];
    NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:@"http://jabber.org/protocol/muc"];
    NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
    [history addAttributeWithName:@"maxstanzas" stringValue:@"50"];
    [x addChild:history];
    [presence addChild:x];
    [[self xmppStream] sendElement:presence];
}

最后一个是

-(void)createGroup
{
    @try {
        NSString *username=@"user_3";//[self.userDefault valueForKey:@"userid"];

        NSXMLElement *presenceElement=[NSXMLElement elementWithName:@"presence"];

        [presenceElement addAttributeWithName:@"type" stringValue:@"groupchat"];

        [presenceElement addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@%@",username,HostName]];

        [presenceElement addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"testGroup@conference.%@/%@",HostName,username]];

        NSXMLElement *xElement=[NSXMLElement elementWithName:@"x" xmlns:@"http://jabber.org/protocol/muc"];

        NSXMLElement *historyElement=[NSXMLElement elementWithName:@"history"];

        [xElement addChild:historyElement];

        [presenceElement addChild:xElement];

        [self.xmppStream sendElement:presenceElement];
    }
    @catch (NSException *exception) {
    }


}

请问有人能告诉我如何解决这个问题吗?如果需要在ejjabered配置中进行额外的配置,请也一并告知。


大家好,最终我在这里找到了解决方案:https://dev59.com/OGbWa4cB1Zd3GeqPbN2W。 - Rohit Pathak
4个回答

2

1
实际上,XMPP并未提供群组聊天功能,您创建的是一个使用XMPPRoom的聊天室,或者可以说是对话。您无法使用此功能发送离线群组消息。
我已经在http://www.catchbuddies.com/项目中使用其他自定义服务器的帮助实现了群组聊天。
您可以通过一些群组网络服务来创建和配置群组聊天。

是的,它确实是一个非常好的聊天应用程序。 - Vishal Android developer

0

0

您应该检查ejabberd服务器配置的muc设置。 确保muc主机已正确设置。

在我的情况下,我将主机更改为{host,“pub.@HOST@”},然后尝试加入房间“test@conference.@HOST@”,总是出现服务不可用错误,花了我整整一晚才解决。

此外,您可以使用管理员用户的imessage登录到您的jabber服务器,并在运行iOS客户端之前创建聊天室。

将ejabberd日志级别更改为调试可能会有很大帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接