2011-03-31 31 views
1

主題: 嗨,我想開發xmpp聊天應用程序,到目前爲止我已經完成了與xmpp聊天,即。向在線用戶發送和接收消息。但我怎麼能添加另一個在線用戶作爲好友/朋友?以及如何從朋友列表中刪除朋友(使用xmpp)?如何知道有人送我一個朋友請求(XMPP) 技術:iphone的applcation編程 語言:Objective C的在iphone sdk中管理使用xmpp的朋友?

回答

1

XMPP服務器管理你的好友列表(名冊管理),所以你必須發送訂閱/取消訂閱數據包到XMPP服務器以添加或刪除好友。請參閱XMPP RFC(rfc-3921)中的部分8.2,瞭解您必須發送的XMPP消息的格式以及必須處理的服務器響應。

這裏是鏈接到XMPP RFC(參見8.2節)下面的代碼

http://xmpp.org/rfcs/rfc3921.html

+0

但我怎麼能從xmpp iphone sdk做那些事?我有xmpp iphone sdk,我可以發送好友請求並從好友請求中刪除,但我無法獲得請求通知和響應請求,即。接受或拒絕請求..... – Matrix 2011-03-31 14:17:02

+0

您正在使用哪個SDK?一些開源框架? – Tayyab 2011-04-01 09:45:48

0

用來發送好友request.Its爲我工作目前。用戶名和電子郵件ID取決於你的openfire設置。

XMPPJID * newBuddy = [XMPPJID jidWithString:@「friendsemailid or username」];

[xmppRoster addUser:newBuddy withNickname:nil];

-1
1.You can add a new friend through this code in didReceivePresence delegate 
else if ([presenceType isEqualToString:@"subscribe"]) 
     { 
      NSXMLElement *presenceToRequest = [NSXMLElement elementWithName:@"presence"]; 
      [presenceToRequest addAttributeWithName:@"type" stringValue:@"subscribed"]; 
      [presenceToRequest addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@", [presence fromStr]]]; 
      [presenceToRequest addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@", [presence toStr]]]; 
      [[self xmppStream] sendElement:presenceToRequest]; 
     } 
2.You can send friend request through XMPPRoster method 
    [xmppRoster addUser:[XMPPJID jidWithString:friendJID] withNickname:friendNickName]; 
3.In didReceivePresence delegate you can your friend request either you want to accept or reject a friendrequest. 

I hope this information helps you to solve your issues.enter code here 
+0

第3點相當不清楚你能解釋一下嗎?你能提供一些代碼嗎? – 2015-03-04 13:37:10