问题
I am new to XMPP. I'm using XMPP and Open fire server for my chat app. The application is working but now I want to get message delivery receipt. I'm using the following code for that,
in setupStream
:
xmppMessageDeliveryRecipts = [[XMPPMessageDeliveryReceipts alloc] initWithDispatchQueue:dispatch_get_main_queue()];
xmppMessageDeliveryRecipts.autoSendMessageDeliveryReceipts = YES;
xmppMessageDeliveryRecipts.autoSendMessageDeliveryRequests = YES;
[xmppMessageDeliveryRecipts activate:xmppStream];
And in sendMessage
:
NSString *messageID=[xmppStream generateUUID];
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"id" stringValue:messageID];
[message addAttributeWithName:@"to" stringValue:myJID];
[message addChild:body];
But i can't get message delivery receipt. How can I get it? Anybody knows?
回答1:
You are already receiving delivery receipt responses, but XMPPMessageDeliveryReceipts
module does not handle it automatically. You need to store all incoming and outgoing messages (check XMPPMessageArchiving
module, it can save messages in the XMPPMessageArchiving_CoreDataStorage
instance), check if message hasReceiptResponse
(defined in XMPPMessage+XEP_0184
category), find the message id in the receipt response and mark corresponding message as "delivered" in the message storage (you may need to add new property e.g. "delivered" to XMPPMessageArchivingCoreDataObject
if you will use this module, or make your own storage mechanism)
来源:https://stackoverflow.com/questions/25887754/cant-get-message-delivery-receipt-in-xmpp