菜鸟教程小白 发表于 2022-12-13 12:53:28

ios - 如何在 xmpp 框架中获取消息已读/未读报告?


                                            <p><p>您好,我正在开发聊天应用程序,所以我正在使用 xmpp 框架。聊天工作正常,但如何在 whatsapp、facebook 等中获得消息传递,我搜索了我发现这里的一些文档是我现在的代码已实现</p>

<p>在连接方法中</p>

<pre><code>XMPPMessageDeliveryReceipts* xmppMessageDeliveryRecipts = [ initWithDispatchQueue:dispatch_get_main_queue()];
xmppMessageDeliveryRecipts.autoSendMessageDeliveryReceipts = YES;
xmppMessageDeliveryRecipts.autoSendMessageDeliveryRequests = YES;
;
</code></pre>

<p>在发送消息方法中添加了这一行</p>

<pre><code>NSXMLElement *request = ;
;
;
;
</code></pre>

<p>但是这是用于消息传递与否我们如何检查传递的消息是否已读我已经看到这些扩展 XEP-0184、XEP-0333 但我不知道如何实现已读/未读消息。请帮帮我</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果您想获取已读回执,而不是发送自动消息传递回执,而是在用户阅读该消息时发送它。每条消息都有其对应的 message_id。使用该 message_id 发送已阅读特定消息的送达回执。因此,请评论以下行</p>

<pre><code>//xmppMessageDeliveryRecipts.autoSendMessageDeliveryReceipts = YES;
</code></pre>

<p>我通过在消息实体中添加“chatStatus”属性解决了这个问题。对于发件人,我将 chatStatus 的值保持为已发送、未发送或已接收(是否被另一方接收)。对于接收方,我将值保持为已读或未读(我是否已阅读消息,因此对于未读消息,我可以发送已读回执)。</p>

<p>点击发送按钮:</p>

<pre><code>//Save to your Message Entity

NSMutableDictionary *m = [ init];
;
;
;
;
;
forKey:@&#34;timeStamp&#34;];
;
;

if (!Is_InternetAvailable]) {
;
}
else{
;
}
[ saveUserMessage:m];
}
</code></pre>

<p>在 cellForRowAtIndexPath 中:</p>

<pre><code>if () {//If I have sent the message

      // Mine bubble
      if ([ isEqualToString:unsent]) {
            //set unsent image
      }
      else if ([ isEqualToString:sent]){
            //set sent image
      }
      else if ([ isEqualToString:received]){
          //set Received Image
      }
    }
    else{
      // Other Bubble , Notify them that you have read the message if it is unread/new message

      if ([ isEqualToString:unread]) {

            //send read receipt
                NSXMLElement *receivedelement = ;

                NSXMLElement *message = ;
                ;
                ;
                ];
                ;

                //XMPPMessage *generatedReceiptResponse = [ generateReceiptResponse];
                [[ xmppStream] sendElement:message];

                // update message entity
                ];
      }
    }
</code></pre>

<p>最后当你在didReceiveMessage中收到delivery Receipt时,将chatStatus更新为received</p>

<pre><code>- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message{

if () {//message read
//Update database message entity
];
}
}
</code></pre>

<p>您可以根据需要设置 chatStatus 的值。至于未发送的消息,我已将其设置为在 didSendMessage 委托(delegate)中发送。</p>

<p>希望对你有帮助!!</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在 xmpp 框架中获取消息已读/未读报告?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/35244647/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/35244647/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在 xmpp 框架中获取消息已读/未读报告?