This topic describes how to obtain a friend list. Here, it mainly describes the functions and interfaces for subsequent updates.
First, provide the core code
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()];
This code has been introduced in the previous chapter, mainly to get friend information, which calls back
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 }
We changed the obtained friend information to the self. Roster array.
XMPP development tutorial (4)-getting friends list