xmpp消息回執(6)

原始地址:XMPPFrameWork IOS 開發(七)消息回執html

請參考:XEP-0184協議 app

協議內容:oop

 

發送消息時附加回執請求測試

 

  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>  

 

代碼實現spa

 

  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];  

 

收到回執請求的消息,發送回執.net

 

  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>  

 

 

代碼實現xml

 

    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. }  
相關文章
相關標籤/搜索