-2

我写了这段代码来创建房间。使用它,我在 openfire 中创建了房间。

-(void)createGroup:(NSString*)groupName
{
      XMPPRoomCoreDataStorage *rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];            
      xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@/%@",groupName,@"server",self.strUsername]] dispatchQueue:dispatch_get_main_queue()];

      [xmppRoom activate:[self xmppStream]];
      [xmppRoom joinRoomUsingNickname:@"nickname" history:nil];
      [xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
      [self performSelector:@selector(ConfigureNewRoom) withObject:nil afterDelay:5];   
}
-(void)ConfigureNewRoom
{
    [xmppRoom fetchConfigurationForm];
    [xmppRoom configureRoomUsingOptions:nil];
}

现在我想在组中添加好友/用户。那么我该怎么做呢?提前致谢。

4

2 回答 2

1

// 使用它就完成了

    XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
    NSString *strJid = [NSString stringWithFormat:@"%@@conference.%@/%@",groupname,strHostname,self.strUsername];
    self.xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemoryStorage jid:[XMPPJID jidWithString:strJid] dispatchQueue:dispatch_get_main_queue()];
    [self.xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [self.xmppRoom activate:self.xmppStream];
    [self.xmppRoom joinRoomUsingNickname:self.strUsername history:nil];

    //inviting
    NSString *strInvitedUserName = [NSString stringWithFormat:@"%@@%@",personName,strHostname];
    [self.xmppRoom inviteUser:[XMPPJID jidWithString:strInvitedUserName] withMessage:message];
于 2014-03-31T07:05:37.637 回答
-1

您可以通过以下方式将其添加到您的花名册中:

[[[self appDelegate] xmppRoster] addUser:[XMPPJID jidWithString:@"userName"] withNickname:[NSString stringWithFormat:@"%@ %@", firstName, lastName] groups:[NSArray arrayWithObjects:@"general", nil]];

并检查它:

XMPPRosterCoreDataStorage *xmppRosterStorage = [[self appDelegate] xmppRosterStorage];
BOOL knownUser = [xmppRosterStorage userExistsWithJID:[XMPPJID jidWithString:@"userName"] xmppStream:[self xmppStream]];
于 2013-09-22T15:15:35.227 回答