Xmppframework iOS development (4) getting messages and friends offline

Source: Internet
Author: User

Original address: xmppframework iOS development (4)

Message

// Receive the message-(void) xmppstream :( xmppstream *) sender didreceivemessage :( xmppmessage *) Message {// nslog (@ "message = % @", message ); // message content nsstring * MSG = [[Message elementforname: @ "body"] stringvalue]; // message sender nsstring * From = [[Message attributeforname: @ "from"] stringvalue];/***** here ***** // The Notification chat page contains new messages, which need to be processed}

Send message

 
// XML format for sending a message <message from = 'sender account' to = 'receiver account' type = 'chat'> <body> Hello World </body> </message>

//CodeAssembly

Nsstring * message = @ "Hello World"; nsxmlelement * Body = [nsxmlelement elementwithname: @ "body"]; [Body setstringvalue: Message]; // generate the XML message document nsxmlelement * MEs = [nsxmlelement elementwithname: @ "message"]; // Message Type [mes addattributewithname: @ "type" stringvalue: @ "chat"]; // who will send the message to [mes addattributewithname: @ "to" stringvalue: @ "recipient account"]; // who will send the message [mes addattributewithname: @ "from" stringvalue: @ "sender account"]; // combine [mes addchild: body]; // send a message [[self xmppstream] sendelement: MES];

Online/offline notifications of friends

-(Void) xmppstream :( xmppstream *) sender didreceivepresence :( xmpppresence *) Presence {// obtain the friend status nsstring * presencetype = [presence type]; // online/offline // The current user nsstring * userid = [[Sender myjid] user]; // The online user nsstring * presencefromuser = [[presence from] user]; /* // if you are not yourself, you 'd better add else here if you are not yourself. If you are offline, call the online protocol xmpppresence * presence = [xmpppresence presence]; [[self xmppstream] sendelement: Presence]; */If (! [Presencefromuser isinclutostring: userid]) {// user online if ([presencetype isinclutostring: @ "available"]) {// The list and database must be changed accordingly} else if ([presencetype isequaltostring: @ "unavailable"]) // The user is offline {// The list and database must be changed accordingly }}}

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.