• xmpp消息回执(6)


    原始地址:XMPPFrameWork IOS 开发(七)消息回执

    请参考:XEP-0184协议 

    协议内容:

    发送消息时附加回执请求

    1. <message  
    2.     from='northumberland@shakespeare.lit/westminster'  
    3.     id='richard2-4.1.247'  
    4.     to='kingrichard@royalty.england.lit/throne'>  
    5.   <body>My lord, dispatch; read o'er these articles.</body>  
    6.   <request xmlns='urn:xmpp:receipts'/>  
    7. </message>  

    代码实现

    1. NSString *siID = [XMPPStream generateUUID];  
    2. //发送消息  
    3. XMPPMessage *message = [XMPPMessage messageWithType:@"chat" to:jid elementID:siID];  
    4. NSXMLElement *receipt = [NSXMLElement elementWithName:@"request" xmlns:@"urn:xmpp:receipts"];  
    5. [message addChild:receipt];  
    6. [message addBody:@"测试"];  
    7. [self.xmppStream sendElement:message];  

    收到回执请求的消息,发送回执

    1. <message  
    2.     from='kingrichard@royalty.england.lit/throne'  
    3.     id='bi29sg183b4v'  
    4.     to='northumberland@shakespeare.lit/westminster'>  
    5.   <received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>  
    6. </message>  

    代码实现

      1. - (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message  
      2. {     
      3.     //回执判断  
      4.     NSXMLElement *request = [message elementForName:@"request"];  
      5.     if (request)  
      6.     {  
      7.         if ([request.xmlns isEqualToString:@"urn:xmpp:receipts"])//消息回执  
      8.         {  
      9.             //组装消息回执  
      10.             XMPPMessage *msg = [XMPPMessage messageWithType:[message attributeStringValueForName:@"type"] to:message.from elementID:[message attributeStringValueForName:@"id"]];  
      11.             NSXMLElement *recieved = [NSXMLElement elementWithName:@"received" xmlns:@"urn:xmpp:receipts"];  
      12.             [msg addChild:recieved];  
      13.               
      14.             //发送回执  
      15.             [self.xmppStream sendElement:msg];  
      16.         }  
      17.     }else  
      18.     {  
      19.         NSXMLElement *received = [message elementForName:@"received"];  
      20.         if (received)  
      21.         {  
      22.             if ([received.xmlns isEqualToString:@"urn:xmpp:receipts"])//消息回执  
      23.             {  
      24.                 //发送成功  
      25.                 NSLog(@"message send success!");  
      26.             }  
      27.         }  
      28.     }  
      29.       
      30.     //消息处理  
      31.     //...  
      32. }  
  • 相关阅读:
    Deployment.yaml文件
    Python 闭包
    github使用方法(一)
    7.Python 正则表达式学习笔记
    kindle网络爬虫续集
    windows下如何快速搭建web.py开发框架
    Python强大的自省简析
    11--Python 备份文件程序
    10- python 网络爬虫分析
    Python基础学习7---异常处理
  • 原文地址:https://www.cnblogs.com/yulang314/p/3705608.html
Copyright © 2020-2023  润新知