Xmppframework for iOS client (2) connecting to the server

Source: Internet
Author: User

The first step is to generate an xmppstream object and set the delegate

_ XmppStream = [[XMPPStreamalloc] init];

[_ XmppStreamaddDelegate: selfdelegateQueue: dispatch_get_main_queue ()];

Step 2: Set the login account name and server name

NSString * userId = @ "test1@mini.local"; // username for login

NSString * server = @ "mini. local "; // @" 127.0.0.1 "; // use the server name or IP address, it is recommended to use the IP address, in the name of the server with their own mistake with the admin@mini.local (Server login account name) I haven't reflected it for a long time. It's really big.

[_ XmppStreamsetMyJID: [XMPPJIDjidWithString: userId];

[_ XmppStream setHostName: server];

// Start the server connection operation

NSError * error = nil;

BFlag = [_ xmppStream connect: & error];

// After the connection operation is started, the callback function (delegate function)

-(Void) xmppStreamWillConnect :( XMPPStream *) sender will be called, indicating that it will be connected

-(Void) xmppStreamDidConnect :( XMPPStream *) sender // log on to the server successfully

{

NSError * error = nil;

// Verify the account password

NSString * password = @ "test1 ";

BOOL bRes = [_ xmppStream authenticateWithPassword: password error: & error];

}

// Callback function verified

-(Void) xmppStreamDidAuthenticate :( XMPPStream *) sender

{

XMPPPresence * presence = [XMPPPresencepresence];

[[SelfxmppStream] sendElement: presence]; // send online notification

}

// Callback for verification failure

-(Void) xmppStream :( XMPPStream *) sender didNotAuthenticate :( NSXMLElement *) error

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.