XMPP登录注册好友群组_实战教学3_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > XMPP登录注册好友群组_实战教学3

XMPP登录注册好友群组_实战教学3

 2014/10/9 12:05:40  Dylan.Alice  程序员俱乐部  我要评论(0)
  • 摘要://Roster我们继续写获取好友列表.h1/*!2*@AuthorDylan.3*4*Roster5*/67typedefvoid(^refreshRosterListFailure)(id);8typedefvoid(^Rosterlist)(id);910/*!11*@AuthorDylan.12*13*requestforrosterlist.IQ14*/15-(void)refreshRosterList:(Rosterlist)success16failure:
  • 标签:

// Roster

我们继续写 获取好友列表

.h

 1 /*!
 2  *  @Author Dylan.
 3  *
 4  *  Roster
 5  */
 6 
 7 typedef void (^refreshRosterListFailure) (id);
 8 typedef void (^Rosterlist) (id);
 9 
10 /*!
11  *  @Author Dylan.
12  *
13  *  request for roster list. IQ
14  */
15 - (void)refreshRosterList: (Rosterlist)success
16                   failure: (refreshRosterListFailure)failure;
17 @property (nonatomic, strong) NSMutableDictionary * rosterDict;

.m

 1 #pragma mark - rosterList
 2 
 3 - (void)initRosterlist {
 4     self.rosterDict = [NSMutableDictionary dictionary];
 5 }
 6 
 7 - (void)refreshRosterList: (Rosterlist)success
 8                   failure: (refreshRosterListFailure)failure {
 9     
10     // call back
11     self.refreshSuccess = success;
12     self.refreshFailure = failure;
13     
14     NSXMLElement * query = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:roster"];
15     NSXMLElement * iq = [NSXMLElement elementWithName:@"iq"];
16     
17     XMPPJID * myJID = self.xmppStream.myJID;
18     [iq addAttributeWithName:@"from" stringValue:myJID.description];
19     [iq addAttributeWithName:@"to" stringValue:myJID.domain];
20     [iq addAttributeWithName:@"id" stringValue:@"123456"];
21     [iq addAttributeWithName:@"type" stringValue:@"get"];
22     [iq addChild:query];
23     
24     [self.xmppStream sendElement:iq];
25 }
26 
27 - (void)xmppStream:(XMPPStream *)sender didFailToSendIQ:(XMPPIQ *)iq error:(NSError *)error {
28     self.refreshFailure(error);
29 }
30 
31 // get user list
32 - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq {
33     
34     // kind of result
35     if ([@"result" isEqualToString:iq.type]) {
36         NSXMLElement * query = iq.childElement;
37         
38         if ([@"query" isEqualToString:query.name]) {
39             NSArray * items = [query children];
40             for (NSXMLElement * item in items) {
41                 NSString * jid = [item attributeStringValueForName:@"jid"];
42                 XMPPJID * xmppJID = [XMPPJID jidWithString:jid];
43                 [_rosterDict setValue:xmppJID forKey:jid];
44             }
45         }
46         // block
47         self.refreshSuccess(_rosterDict);
48         return YES;
49     }
50     
51     NSLog(@"get iq error");
52     return NO;
53 }
54 
55 
56 @end

 

// 顺便写出在点m文件中我写的回掉Block 的属性

 1 @interface ADXMPPConn ()
 2 
 3 /*!
 4  *  @Author Dylan.
 5  *
 6  *  Call back Block
 7  */
 8 @property (nonatomic, copy) connectSuccess connSuccess;
 9 @property (nonatomic, copy) AuthenticateFailure authenFailure;
10 
11 @property (nonatomic, copy) registerSuccess regisSuccess;
12 @property (nonatomic, copy) registerFailure regisFailure;
13 
14 /*!
15  *  call back block
16  */
17 @property (nonatomic, copy) sendSuccess success;
18 @property (nonatomic, copy) sendFailure failure;
19 
20 /*!
21  *  call back block
22  */
23 @property (nonatomic, copy) refreshRosterListFailure refreshFailure;
24 @property (nonatomic, copy) Rosterlist refreshSuccess;
25 
26 @end

 

上一篇: xmpp登录注册好友群组_实战教学4 下一篇: 没有下一篇了!
  • 相关文章
发表评论
用户名: 匿名