2014-03-14 44 views
3

你好,我已經使用的Openfire作爲服務器發送好友請求給用戶,並想送朋友請求我使用下面的代碼使用XMPP和Openfire的

- (XMPPRoster *)xmppRoster { 
    return [[self appDelegate] xmppRoster]; 
} 

-(IBAction)SendFriendRequest:(id)sender 
{ 
    XMPPJID *newBuddy = [XMPPJID jidWithString:@"[email protected]"]; 

    [[[self appDelegate]xmppRoster]addUser:newBuddy withNickname:@"test user 1"]; 
} 

我收到此類型的日誌

<iq xmlns="jabber:client" type="error" to="192.168.4.21/de4fd927"><query xmlns="jabber:iq:roster"><item jid="[email protected]" name="test user 3"></item></query><error code="401" type="auth"><not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></not-authorized></error></iq> 

我無法發送請求到「test1」已經登錄了spark。

任何幫助將是可觀的!

回答

1
  1. 每個XMPP實體,它可以與其它實體交換XMPP包,應該有JID在[email protected]表格,您可以嘗試使用IP地址而不是域名,這是可能的,但有可能會給出意想不到的錯誤。

  2. 您應該在服務器上進行身份驗證,然後才能與其他人交換數據包。

1

這似乎你還沒有初始化在setupStream方法xmppRoster:

請儘量寫在設置流下面的代碼:

xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] initWithInMemoryStore]; 

xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage]; 

xmppRoster.autoFetchRoster = YES; 
xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES; 

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

[xmppRoster activate:xmppStream]; 

希望它會給予一定的幫助

+0

是有什麼辦法將好友請求發送給離線用戶? –

+1

是的,您可以向離線用戶和其他用戶發送好友請求,只要被請求的用戶在線就會收到請求。 這裏是代碼: XMPPJID * newBuddy = [XMPPJID jidWithString:[NSString stringWithFormat:@「[email protected]」]]; [[self xmppRoster] addUser:newBuddy withNickname:Nil]; –