Easy implementation of XMPP Instant Messaging for iOS development

Source: Internet
Author: User

Server and database are installed first

With the server, I'm using OpenFire, the database is MySQL.

Two links recommended here

Configure MySQL with MySQL Workbench

http://justsee.iteye.com/blog/1753467

Configuring the server OpenFire

Http://www.cnblogs.com/xiaodao/archive/2013/04/05/3000554.html

First configure the database and then configure the server.

All two open.

The next XMPP client, which is used to test the

I'm under the Adium.

Down here.

http://xmpp.org/xmpp-software/clients/

Then add the account in Adium, the server will be set up with OpenFire 127.0.0.1, Port 5222

Here OpenFire the server port inside, 5222 is the client connection server

After successful login, you can see that the user is online in OpenFire.

Then another client, I directly with the code, feel trouble did not do interface

Set Xmppstream

Then set the account, at least test, so directly in the Viewdidload wrote

Then is to verify the password, the following method is on-line, these are proxy methods, Remember to set Xmppstream agent

This is the way to receive information, I do not interface, directly print out the accepted information

This method is called if the validation fails.

At first I run the error that always returns XMPP validation failed

Later in OpenFire view username must be with server name

For example, my account is test123, set Jid username is [email protected]

Then run, no error, in OpenFire display already online

Then you can start chatting, the following is the first hair, the above is the previous chat record

Sent a text and a link

Then Xcode outputs

Instant Messaging is the simplest way to get out of the app and the OpenFire backstage will show the offline

Code

#import "ViewController.h"#import "XMPP.h"@interfaceViewcontroller () <XMPPStreamDelegate>@property (nonatomic,strong) Xmppstream*stream;@end@implementationViewcontroller-(Xmppstream *) stream{if(!_stream) {_stream=[[Xmppstream alloc] init];    [_stream adddelegate:self Delegatequeue:dispatch_get_current_queue ()]; }    return_stream;}- (void) viewdidload {[Super viewdidload]; [Self.stream Setmyjid:[xmppjid jidwithstring:@"[email protected]"]]; [Self.stream sethostname:@"127.0.0.1"]; [Self.stream Sethostport:5222]; Nserror*error =Nil; [Self.stream connectwithtimeout:1.0ferror:&ERROR]; if(Error) {NSLog (@"connectwithtimeout:%@", error); }}- (void) Xmppstream: (Xmppstream *) sender Didreceivemessage: (Xmppmessage *) message{NSString*msg = [[Message elementsforname:@"Body"] Lastobject]; NSLog (@"%@", MSG); }- (void) Xmppstreamdidconnect: (Xmppstream *) sender{Nserror*error =Nil; [Self.stream Authenticatewithpassword:@"test123"error:&ERROR]; if(Error) {NSLog (@"Authenticatewithpassword:%@", error); }}- (void) Xmppstreamdidauthenticate: (Xmppstream *) sender{xmpppresence*presence =[xmpppresence presence]; [Self.stream sendelement:presence];}- (void) Xmppstream: (Xmppstream *) sender Didnotauthenticate: (Ddxmlelement *) error{NSLog (@"didnotauthenticate:%@", error);}

Easy implementation of XMPP Instant Messaging for iOS development

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.