xmpp-Registration and Login

Source: Internet
Author: User

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

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.