XMPP Programming iOS platform (i) Configuration and login

Source: Internet
Author: User

Here's a record of the process I'm configuring XMPP

First download xmpp:https://github.com/robbiehanson/xmppframework/

Enter the following file into the process:


Adding a dependency framework


To add a dependent path to the XML framework:


The configuration is done. Here's how to log in. Of course, the server to make a good first, if not good to see the previous article.

Login code:

@interface Xmppmodel () <XMPPStreamDelegate> @property (nonatomic, strong) Xmppstream *xmppstream; @end

-(BOOL) connect{    [self setupstream];    Here in order to reduce the number of code so directly here to write dead. It's good to change them directly when you test.    //Obtain the user name and password and server address        locally NSString *userid = @ "Dujia"; Username    nsstring *password = @ "ZXCVBNM";//password    nsstring *server = @ "10.86.102.70";//server IP                    if (![ _xmppstream isdisconnected]) {        return  YES;    }  The following 3 parameters are  user name domain  domain name   resource This ming    xmppjid *jid = [Xmppjid jidwithuser:userid domain : @ "ShenQi" resource:@ "Ework"];        [_xmppstream Setmyjid:jid];    [_xmppstream Sethostname:server];    [_xmppstream sethostport:5222];            Nserror *error = nil;    if (![ _xmppstream connectwithtimeout:3.0 Error:&error]) {        NSLog (@ "%@", Error.userinfo);    }    return YES;} -(void) setupstream{    _xmppstream = [[Xmppstream alloc] init];    [_xmppstream adddelegate:self Delegatequeue:dispatch_get_main_queue ()];    }

The following is a successful callback for the connection. The password is verified in the following steps:

-(void) Xmppstreamdidconnect: (Xmppstream *) sender{    nserror *error = nil;    if (![ Sender authenticatewithpassword:@ "zxcvbnm" Error:&error]) {        NSLog (@ "%@", Error.userinfo);    }    }

This way the server page will appear as follows:


So the landing was successful. Let's talk about quitting.

-(void) gooffline{    xmpppresence *presence = [xmpppresence presencewithtype:@ "unavailable"];    [_xmppstream sendelement:presence];    [_xmppstream disconnect];}

Code Download: Http://pan.baidu.com/s/1hqiUfmG


XMPP Programming iOS platform (i) Configuration and login

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.