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