XMPP Add Delete Friend

Source: Internet
Author: User

At this stage of the communication services, various standards are available, so there will be unable to achieve interconnection, andXMPP (extensible Message and Presence Protocol)The advent of the agreement, the realization of the entire timely Communication service agreement interoperability. With this agreement, the use of any one organization or individual, even if the communication services, can be accessible to other users of the timely communication services to communicate. For exampleGoogleCompany2005Year launched theGoogle Talkis a model based onXmppProtocol for Instant Messaging software. Let's talk a little bit about how to use it simplyXMPP 's friends add

1, in the XMPPFramework.h will need to use the header file open

2. Create a Friend list interface and add friends interface in storyboard

The connection between the two should be noted when creating and adding:

3. Define the query result memory and initialize it.
Nsfetchedresultscontroller *fetch; Appdelegate*Delegate=[uiapplication Sharedapplication].Delegate; //Get ContextNsmanagedobjectcontext * context=[Delegate. Rosterstorage Mainthreadmanagedobjectcontext]; //GET request NsfetchrequestNsfetchrequest * Request=[nsfetchrequest Fetchrequestwithentityname:@"Xmppusercoredatastorageobject"]; //Add Sort fieldNssortdescriptor * Des=[nssortdescriptor Sortdescriptorwithkey:@"Sectionnum"Ascending:yes];        [Request Setsortdescriptors:@[des]]; //to initialize a fetchFetch=[[nsfetchedresultscontroller Alloc] Initwithfetchrequest:request managedobjectcontext:context Sectionnamekeypath:@"Sectionnum"Cachename:nil]; //Set up proxy[Fetch setdelegate:self]; //Start Query[Fetch Performfetch:nil];
4, create the agent method to realize TableView
#pragmaMark-table View Data source-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {returnFetch.sections.count;}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {ID<NSFetchedResultsSectionInfo> sections=Fetch.sections[section]; return[sections numberofobjects];}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:@"tabble" ]; Xmppusercoredatastorageobject* user=[Fetch Objectatindexpath:indexpath]; Cell.textLabel.text=User.displayname; returncell;}//returns the grouped data information, based on the field type, to control the current state-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section{ID<NSFetchedResultsSectionInfo> info=[[Fetch sections] objectatindex:section]; NSString* type=Nil; if([Info.name isequaltostring:@"0"]) {type=@"Online"; }Else{type=@"Offline"; }        returntype;}
5. Delete Friends

-(BOOL) TableView: (UITableView *) TableView Caneditrowatindexpath: (Nsindexpath *) indexpath{returnYES;}//Delete A current friend with a roster object-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) indexpath{if(editingstyle==uitableviewcelleditingstyledelete) {Appdelegate*Delegate=[uiapplication Sharedapplication].Delegate; Xmppusercoredatastorageobject* user=[Fetch Objectatindexpath:indexpath]; [Delegate. Roster RemoveUser:user.jid]; }}
6. Add Friends
-(ibaction) Add {//Get friend nameNSString * name=Self.friends.text; //Get friend nameAppdelegate *Delegate=[uiapplication Sharedapplication].Delegate; Xmppjid* jid=[Xmppjid Jidwithstring:name]; if([Delegate. rosterstorage Userexistswithjid:jid Xmppstream:Delegate. Stream]) {NSLog (@"friends already exist."); }Else{        //Add Friends[Delegate. Roster Subscribepresencetouser:jid]; }}

To learn more about the small partners, you can click to view the source code , run the test yourself.

Inquiries or technical exchanges, please join the official QQ Group: (452379712)

Jerry Education
Source:http://www.cnblogs.com/jerehedu/
This article is the copyright of Yantai Jerry Education Technology Co., Ltd. and the blog Park is shared, welcome reprint, but without the consent of the author must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

XMPP Add Delete Friend

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.