2013-07-18 39 views
-1

我寫了創建空間的代碼。使用這個我創造了openfire的空間。如何在xmpp iphone中添加好友/用戶組?

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

現在我想添加組中的好友/用戶。所以我怎麼做到這一點?提前致謝。

回答

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]; 
-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]]; 
+0

嗨Hayro,Hardik正在詢問如何在聊天室中添加會員。您的答案解釋瞭如何將好友添加到好友列表,但沒有說明如何將其添加到聊天室中。 – Yogi