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