原始地址:XMPPFrameWork IOS 开发(七)消息回执
请参考:XEP-0184协议
协议内容:
发送消息时附加回执请求
- <message
- from='[email protected]/westminster'
- id='richard2-4.1.247'
- to='[email protected]/throne'>
- <body>My lord, dispatch; read o'er these articles.</body>
- <request xmlns='urn:xmpp:receipts'/>
- </message>
代码实现
- 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];
收到回执请求的消息,发送回执
- <message
- from='[email protected]/throne'
- id='bi29sg183b4v'
- to='[email protected]/westminster'>
- <received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>
- </message>
代码实现
- - (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!");
- }
- }
- }
- //消息处理
- //...
- }