XMPP login to register a friend group _ practical tutorial 2, xmpp login Registration

Source: Internet
Author: User

XMPP login to register a friend group _ practical tutorial 2, xmpp login Registration

Message:

Then write

. H

 1 /*! 2  *  @Author Dylan. 3  * 4  *  callback Block 5  */ 6 typedef void(^sendSuccess)(); 7 typedef void(^sendFailure)(id); 8  9 /*!10  *  sendMessageBy model11  */12 - (void)sendMessage: (ADMessageModel *)message13         sendSuccess: (sendSuccess)success14         sendFailure: (sendFailure)failure;15 16 /*!17  *  @Author Dylan.18  *19  *  unRead Msg20  */21 @property (nonatomic, strong) NSMutableDictionary * unReadMsg;22 23 /*!24  *  @Author Dylan.25  *26  *  new Msg27  */28 @property (nonatomic, copy) void (^newMessage) (id);29 30 31 @end

. M

1 # pragma mark-initData 2-(void) initData {3 // data persistence 4 self. unReadMsg = [invalid dictionary]; 5} 6 7 # pragma mark Methods 8-(void) sendMessage: (ADMessageModel *) message 9 sendSuccess: (sendSuccess) success10 sendFailure: (sendFailure) failure {11 12 // set callback block13 self. success = success; 14 self. failure = failure; 15 16 NSXMLElement * body = [NSXMLElement elementWithName: @ "Body"]; 17 [body setStringValue: message. body]; 18 19 // generate XML message Document 20 NSXMLElement * mes = [NSXMLElement elementWithName: @ "message"]; 21 // message Type 22 [mes addAttributeWithName: @ "type" stringValue: @ "chat"]; 23 // to whom 24 [mes addAttributeWithName: @ "to" stringValue: message. to]; 25 // who sent 26 [mes addAttributeWithName: @ "from" stringValue: message. from]; 27 // combination 28 [mes addChild: body]; 29 // send message 30 [self xmppStream] sen DElement: mes]; 31} 32 33 # pragma mark-delegeteMethods34-(void) xmppStream :( XMPPStream *) sender didReceiveMessage :( XMPPMessage *) message {35 36 NSString * body = [[message elementForName: @ "body"] stringValue]; 37 NSString * from = [[message attributeForName: @ "from"] stringValue]; 38 39 if (body! = Nil) {40 41 NSMutableDictionary * msgDict = [NSMutableDictionary dictionary]; 42 ADMessageModel * model = [[ADMessageModel alloc] init]; 43 model. body = body; 44 model. from = from; 45 [msgDict setValue: model forKey: [ADCurrentTime getCurrentTime]; 46 47 if ([from isEqualToString: [[NSUserDefaults standardUserDefaults] stringForKey: CURRENT_CHAT]) {48 49 self. newMessage (msgDict); 50} else {51 // not current chat52 if ([_ unReadMsg. allKeys containsObject: from]) {53 [_ unReadMsg [from] addObject: model]; 54} else {55 [_ unReadMsg setValue: [NSMutableArray arrayWithObject: msgDict] forKey: from]; 56} 57} 58 59} 60} 61 62 @ end

 




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.