Xmppframework for iOS client (3) Add friends

Source: Internet
Author: User

Add Friend code

Initialize xmppStream

_ XmppStream = [[XMPPStreamalloc] init];

// [_ XmppStream setEnableBackgroundingOnSocket: YES];

[_ XmppStreamaddDelegate: selfdelegateQueue: dispatch_get_main_queue ()];

//

_ XmppRosterDataStorage = [[XMPPRosterCoreDataStoragealloc] init];

_ XmppRoster = [[XMPPRosteralloc] initWithRosterStorage: _ xmppRosterDataStorage];

// _ XmppRoster. autoFetchRoster = YES;

// _ XmppRoster. autoAcceptKnownPresenceSubscriptionRequests = YES;

//}

[_ XmppRosteractivate: _ xmppStream];

[_ XmppRosteraddDelegate: selfdelegateQueue: dispatch_get_main_queue ()];

// Add a friend

XMPPJID * frendJID = [XMPPJID jidWithString: strFriendJID];

[_ XmppRoster addUser: frendJID withNickname: nick];

// After the message is added, the friend receives the message and agrees to the following callback:

 

// Receives the friend status

-(Void) xmppStream :( XMPPStream *) sender didReceivePresence :( XMPPPresence *) presence

{

// NSLog (@ "presence = % @", presence );

// Obtain the friend status. subscribed: The unsubscribed request is rejected by verifying the friend's day.

NSString * presenceType = [presence type]; // online/offline

// Current user

NSString * userId = [[sender myJID] user];

// Online user

NSString * presenceFromUser = [[presence from] user];

If (! [PresenceFromUser isinclutostring: userId])

{

// Online status

If ([presenceType isw.tostring: @ "available"])

{

}

Else if ([presenceType isEqualToString: @ "unavailable"]) // offline

{

}

//

}

}

 

 

Related Article

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.