3

我正在为我当前的项目使用robbiehanson/XMPPFramework,我可以向我的花名册中的人发送和接收消息,但现在我必须实现消息传递状态。我知道 xep 它的 0184 并且我也包含在我的项目中,我很难使用它。

我在xep-0184 文档中读到请求元素也必须包含在消息中,所以这是我的代码:

#import "XMPPMessage+XEP_0184.h"
.
.
.
NSXMLElement *body = [NSXMLElement elementWithName:@"body"];

[body setStringValue:messageStr];

NSXMLElement *request = [NSXMLElement elementWithName:@"request" xmlns:@"urn:xmpp:receipts"];

NSXMLElement *message = [NSXMLElement elementWithName:@"message"];

[message addAttributeWithName:@"type" stringValue:@"chat"];

[message addAttributeWithName:@"to" stringValue:[defaults objectForKey:@"chatWith"]]; 
[message addChild:body];
[message addChild:request];
.
.
.
XMPPMessage *xm = [[XMPPMessage alloc]init];
NSLog(@"..1..%d",[xm hasReceiptRequest]);        // Result = 0
NSLog(@"..2..%d",[xm hasReceiptResponse]);       // Result = 0
NSLog(@"..3..%@",[xm extractReceiptResponseID]); // Result = (null)
NSLog(@"..4..%@",[xm generateReceiptResponse]);  // Result = <message><received xmlns="urn:xmpp:receipts"></received></message>

请帮助我如何获得消息传递状态。

4

1 回答 1

2

I think you forgot to add the module itself. When you want to add an XMPPModule like XMPPMessageDeliveryReceipts you should add it to the XMPPStream object first, then you can use its functions.

Do the following:

// Setup Message Delivery Recipts Object
XMPPMessageDeliveryReceipts* xmppMessageDeliveryRecipts = [[XMPPMessageDeliveryReceipts alloc] initWithDispatchQueue:dispatch_get_main_queue()];
xmppMessageDeliveryRecipts.autoSendMessageDeliveryReceipts = YES;
xmppMessageDeliveryRecipts.autoSendMessageDeliveryRequests = YES;

[xmppMessageDeliveryRecipts activate:xmppStream];

When xmppStream is your main XMPPFramework object.

Hope i helped.

于 2013-06-08T19:47:26.387 回答