(转载)XMPPFrameWork IOS 开发(七)消息回执

原始地址:XMPPFrameWork IOS 开发(七)消息回执
请参考:XEP-0184协议 
协议内容:

发送消息时附加回执请求
[cpp] view plain copy print?
  
  My lord, dispatch; read o'er these articles.  
    
  
代码实现
[cpp] view plain copy print?
NSString *siID = [XMPPStream generateUUID];  
//发送消息  
XMPPMessage *message = [XMPPMessage messageWithType:@"chat" to:jid elementID:siID];  
NSXMLElement *receipt = [NSXMLElement elementWithName:@"request" xmlns:@"urn:xmpp:receipts"];  
[message addChild:receipt];  
[message addBody:@"测试"];  
[self.xmppStream sendElement:message];  

收到回执请求的消息,发送回执
[cpp] view plain copy print?
  
    
  

代码实现
[cpp] view plain copy print?
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message  
{     
    //回执判断  
    NSXMLElement *request = [message elementForName:@"request"];  
    if (request)  
    {  
        if ([request.xmlns isEqualToString:@"urn:xmpp:receipts"])//消息回执  
        {  
            //组装消息回执  
            XMPPMessage *msg = [XMPPMessage messageWithType:[message attributeStringValueForName:@"type"] to:message.from elementID:[message attributeStringValueForName:@"id"]];  
            NSXMLElement *recieved = [NSXMLElement elementWithName:@"received" xmlns:@"urn:xmpp:receipts"];  
            [msg addChild:recieved];  
              
            //发送回执  
            [self.xmppStream sendElement:msg];  
        }  
    }else  
    {  
        NSXMLElement *received = [message elementForName:@"received"];  
        if (received)  
        {  
            if ([received.xmlns isEqualToString:@"urn:xmpp:receipts"])//消息回执  
            {  
                //发送成功  
                NSLog(@"message send success!");  
            }  
        }  
    }  
      
    //消息处理  
    //...  
}  

你可能感兴趣的:((转载)XMPPFrameWork IOS 开发(七)消息回执)