标签:blog io os ar for sp div on log
这章节主要是介绍如何获取好友列表,在这里主要是做功能部分,后续更新的时候就将界面也做上去
首先提供下核心代码
1 xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init];
2 // xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] initWithInMemoryStore];
3
4 xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage];
5
6 xmppRoster.autoFetchRoster = YES;
7 xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;
8 [xmppRoster activate:xmppStream];
9 [xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
这段代码上个章节已经介绍过了,主要是获取好友信息,这个时候它会回调
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 #pragma mark ReceiveIQ
3 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4
5 - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
6 {
7 NSLog(@"%@: %@", THIS_FILE, THIS_METHOD);
8
9 if ([@"result" isEqualToString:iq.type]) {
10 NSXMLElement *query = iq.childElement;
11 if ([@"query" isEqualToString:query.name]) {
12 NSArray *items = [query children];
13 for (NSXMLElement *item in items) {
14 NSString *jid = [item attributeStringValueForName:@"jid"];
15 XMPPJID *xmppJID = [XMPPJID jidWithString:jid];
16 [self.roster addObject:xmppJID];
17 }
18 }
19 }
20
21 return NO;
22 }
我们将获取的好友信息变存在self.roster这个数组中了。
标签:blog io os ar for sp div on log
原文地址:http://www.cnblogs.com/guchengfengyun/p/4049074.html