IOS XMPP uses Xmppframewok (quad): Send and receive messages

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/dyingbleed/archive/2013/05/16/3075105.html

Send and receive messages

Receiving messages

By implementing

-(void) Xmppstream: (xmppstream *) sender Didreceivemessage: (xmppmessage *) message;

Method

When the content of the <message/> Tag is received, the Xmppframework framework callbacks the method

Depending on the XMPP protocol, the contents of the message body are stored in the label <body/>

-(void) Xmppstream: (Xmppstream *) sender Didreceivemessage: (xmppmessage *) message {    NSString *messagebody = [[ Message elementforname:@ "Body"] stringvalue];}

Send Message

To send a message, we need to place the data in the <message/> Tag, based on the XMPP protocol, for example:

<message type= "Chat" to= "[email protected]" >

<body>hello world!<body/>

<message/>

-(void) SendMessage: (NSString *) message Touser: (NSString *) User {    nsxmlelement *body = [Nsxmlelement Elementwithnam e:@ "Body"];    [Body setstringvalue:message];    Nsxmlelement *message = [nsxmlelement elementwithname:@ "message"];    [Message addattributewithname:@ "type" stringvalue:@ "chat"];    NSString *to = [NSString stringwithformat:@ "%@ @example. com", user];    [Message addattributewithname:@ "to" stringvalue:to];    [Message addchild:body];    [Self.xmppstream sendelement:message];}

IOS XMPP uses Xmppframewok (quad): Send and receive messages

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.