您的位置:首页 > 移动开发 > IOS开发

IOS使用XMPP最新教程(五)添加好友和接受好友请求

2015-10-12 12:49 267 查看
加好友要使用Roster类,整个加好友的过程比较简单,就是下面的代码。

XMPPRoster * xmppRoster = [self xmppRoster];

[xmppRoster subscribePresenceToUser:jid];

注意jid是这样生成的:

XMPPJID *jid = [XMPPJID jidWithString:@"3@127.0.0.1"];

然后系统会回调这个函数

- (void)didReceivePresenceSubscriptionRequest:(XMPPPresence *)presence

但是经常会发现这个函数并不执行,解决办法情看我的另一篇帖子XMPP didReceivePresenceSubscriptionRequest函数不执行解决办法

presence里面包含了请求的各种信息

@interface XMPPPresence : XMPPElement

// Converts an NSXMLElement to an XMPPPresence element in place (no memory allocations or copying)

+ (XMPPPresence *)presenceFromElement:(NSXMLElement *)element;

+ (XMPPPresence *)presence;

+ (XMPPPresence *)presenceWithType:(NSString *)type;

+ (XMPPPresence *)presenceWithType:(NSString *)type to:(XMPPJID *)to;

- (id)init;

- (id)initWithType:(NSString *)type;

- (id)initWithType:(NSString *)type to:(XMPPJID *)to;

- (NSString *)type;

- (NSString *)show;

- (NSString *)status;

- (int)priority;

- (int)intShow;

- (BOOL)isErrorPresence;

@end

通过源码可以看到它是继承自XMPPElement的,所以取信息的方法一样。

然后就是接受请求的函数:

[xmppRoster acceptPresenceSubscriptionRequestFrom:jid andAddToRoster:YES];//YES是向对方发送好友请求
拒绝的函数:

[xmppRoster rejectPresenceSubscriptionRequestFrom:jid];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: