码迷,mamicode.com
首页 > 其他好文 > 详细

xmpp好友请求5

时间:2014-10-10 13:00:34      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   strong   sp   

实现好友请求

.m

 1 #pragma mark - rosterHandle
 2 
 3 // initRoster
 4 - (void)initRoster {
 5     self.xmppRosterMemory = [[XMPPRosterMemoryStorage alloc] init];
 6     self.xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:self.xmppRosterMemory];
 7     [_xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
 8     [_xmppRoster activate:self.xmppStream];
 9 }
10 
11 - (void)addFriend: (NSString *)accountName {
12     [_xmppRoster addUser:[XMPPJID jidWithString:[accountName stringByAppendingString:DOMAINS]] withNickname:nil];
13 }
14 
15 - (void)removeFriend: (NSString *)accountName {
16     [_xmppRoster removeUser:[XMPPJID jidWithString:[accountName stringByAppendingString:DOMAINS]]];
17 }
18 
19 // call back
20 - (void)dealWithFriendAsk: (BOOL)isAgree
21               accountName: (NSString *)accountName {
22     XMPPJID * jid=[XMPPJID jidWithString:[NSString stringWithFormat:@"%@%@",accountName,DOMAINS]];
23     if(isAgree){
24         [self.xmppRoster acceptPresenceSubscriptionRequestFrom:jid andAddToRoster:NO];
25     }else{
26         [self.xmppRoster rejectPresenceSubscriptionRequestFrom:jid];
27     }
28 
29 }
30 
31 #pragma mark addFriendDelegateMethods
32 - (void)xmppRoster:(XMPPRoster *)sender didReceivePresenceSubscriptionRequest:(XMPPPresence *)presence {
33     
34     NSString *presenceFromUser =[NSString stringWithFormat:@"%@", [[presence from] user]];
35     if (self.acceptOrDenyFriend != nil) {
36         BOOL isAgree = self.acceptOrDenyFriend(presenceFromUser);
37         [self dealWithFriendAsk:isAgree accountName:presenceFromUser];
38     }
39 }
40 
41 @end

.h

 1 /*!
 2  *  @Author Dylan.
 3  *
 4  *  addRoster.
 5  */
 6 // if you want to deny or add friend. please call this block
 7 @property (nonatomic, copy) BOOL (^acceptOrDenyFriend) (NSString *);
 8 @property (nonatomic, strong) XMPPRoster * xmppRoster;
 9 
10 /*!
11  *  @Author Dylan. Methods
12  */
13 - (void)addFriend: (NSString *)accountName;
14 - (void)removeFriend: (NSString *)accountName;

 

xmpp好友请求5

标签:style   blog   color   io   os   ar   for   strong   sp   

原文地址:http://www.cnblogs.com/Dylan-Alice/p/Dylan_XMPP5.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!