XMPP Add Delete Friend

Source: Internet
Author: User

At this stage of communication services, all kinds of standards have, so there will be unable to achieve interconnection, and XMPP (extensible Message and Presence Protocol) protocol, the realization of the entire timely Communication Service protocol 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. Google Talk, for example, 2005 , is an XMPP protocol-based instant messaging software. Let's talk a little bit about how to easily add a friend with XMPP

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 Context    Nsmanagedobjectcontext * context=[delegate.rosterstorage Mainthreadmanagedobjectcontext];        Get request Nsfetchrequest    nsfetchrequest * request=[nsfetchrequest fetchrequestwithentityname:@ " Xmppusercoredatastorageobject "];        Add Sort field    nssortdescriptor * des=[nssortdescriptor sortdescriptorwithkey:@ "Sectionnum" ascending:yes];    [Request Setsortdescriptors:@[des]];        The fetch is initialized    Fetch=[[nsfetchedresultscontroller alloc] initwithfetchrequest:request managedobjectcontext: Context sectionnamekeypath:@ "Sectionnum" cachename:nil];        Set Agent    [Fetch setdelegate:self];        Start Query    [fetch PERFORMFETCH:NIL];
4, create the agent method to realize TableView
#pragma mark-table View data source-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {return FETCH.S Ections.count;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {id<    Nsfetchedresultssectioninfo> Sections=fetch.sections[section]; return [sections numberofobjects];} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {Uitablevie     Wcell *cell = [TableView dequeuereusablecellwithidentifier:@ "tabble"];    Xmppusercoredatastorageobject * User=[fetch Objectatindexpath:indexpath];            Cell.textlabel.text=user.displayname; return cell;} Returns the grouped data information, depending 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"]) {[email protected] "online";}else {[email protected] "offline"; } return type;}
5. Delete Friends

-(BOOL) TableView: (UITableView *) TableView Caneditrowatindexpath: (Nsindexpath *) indexpath{    return YES; Delete the current friend through the 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 name    NSString * NAME=SELF.FRIENDS.TEXT;     Get friend name    appdelegate * delegate=[uiapplication sharedapplication].delegate;    Xmppjid * Jid=[xmppjid Jidwithstring:name];    if ([Delegate.rosterstorage Userexistswithjid:jid XmppStream:delegate.stream]) {        NSLog (@ "friend already exists");    } 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://blog.csdn.net/jerehedu/
This article is the copyright of Yantai Jerry Education Technology Co., Ltd. and CSDN Common, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.