Can't get message delivery receipt in XMPP

扶醉桌前 提交于 2019-12-11 03:16:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!