XMPP development tutorial (4)-getting friends list

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.