Import Header File XMPPFramework.h
Add Agent Xmppstreamdelegate
@property (strong,nonatomic) Xmppstream *xmppstream;
@property (assign,nonatomic) BOOL isregister;
@property (strong,nonatomic) Nsstring*user,*pwd,*hostname,*domain;
@property (assign,nonatomic) UInt16 port;
Downline-(void) logout{ //1. User downline NSLog (@ "logout user"); Xmpppresence *presene=[xmpppresence presencewithtype:@ "unavailable"]; Set the downline status [_xmppstream sendelement:presene]; 2. Disconnect [_xmppstream disconnect];}
Start connection to chat server-(BOOL) Connectwithusername: (nsstring*) Username andpwd: (nsstring*) pwd andhostname: (nsstring*) hostname Anddomain: (nsstring*) domain Andhostport: (UInt16) port andisregister: (BOOL) isregister{ Self.hostname = hostname; Self.port = port; Self.domain = domain; Self.user = username; Self.pwd = pwd; Self.isregister = isRegister; & nbsp; Self.xmppstream = [[Xmppstream alloc] init]; //Set Agent [Self.xmppstream Adddelegate:self delegatequeue:dispatch_get_global_queue (0, 0)]; //Set Chat server address Self.xmppstream. HostName = hostname; //Set Chat server port default is 5222 Self.xmppStream.hostPort = port; //Set Jid is username xmppjid *jid = [Xmppjid jidwithuser: Username domain:domain resource:@ "Test"]; Self.xmppStream.myJID = jid; Nserror * ERROR = nil; //verify Connection [Self.xmppstream connectwithtimeout: Xmppstreamtimeoutnone error:&error]; if (error) { NSLog (@ "Connection failed:%@", error); return no; } else { return YES; }}// Connection Successful agent function-(void) Xmppstreamdidconnect: (Xmppstream *) sender{NSLog (@ "Connection succeeded"); if (self.isregister) {nserror* error = nil; [Sender RegisterWithPassword:self.pwd error:&error]; if (Error) {NSLog (@ "Registration failed 1,%@", error); }} else {nserror *error = nil; [Sender AuthenticateWithPassword:self.pwd error:&error]; if (Error) {NSLog (@ "validation failed 1,%@", error); }}//Connection Failed agent function-(void) Xmppstreamdiddisconnect: (Xmppstream *) sender Witherror: (Nserror *) error{NSLog (@ "Connection failed,%@",Error);} Verify Success Agent Function-(void) Xmppstreamdidauthenticate: (Xmppstream *) sender{NSLog (@ "verify success"); 4. Login successful online [self.xmppstream sendelement:[xmpppresence presence]];//user Online}//authentication failed agent function-(void) Xmppstream: (Xmppstream * Sender Didnotauthenticate: (ddxmlelement *) error{NSLog (@ "Verification failed,%@", error);} Registered Success Agent function-(void) Xmppstreamdidregister: (Xmppstream *) sender{NSLog (@ "registered successfully");} Registration failed agent function-(void) Xmppstream: (Xmppstream *) sender Didnotregister: (ddxmlelement *) error{NSLog (@ "registration failed,%@", error);}
xmpp-Registration and Login