2011-03-31 40 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