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

来源:互联网 发布:个人域名需要备案吗 编辑:程序博客网 时间:2024/04/30 13:45

加好友要使用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];






0 0
原创粉丝点击