gpt4 book ai didi

ios - 如何在 XMPP iOS 中获取消息传递、已读、失败和未读消息数? ( swift 3.0)

转载 作者:搜寻专家 更新时间:2023-11-01 06:32:12 25 4
gpt4 key购买 nike

我正在开发聊天应用程序,因为我遇到了两种情况。

1) 如何获取消息状态,如已送达、已读等。 我做了以下事情:

self.xmppMessageDeliveryRecipts = XMPPMessageDeliveryReceipts(dispatchQueue: DispatchQueue.main)
self.xmppMessageDeliveryRecipts!.autoSendMessageDeliveryReceipts = true
self.xmppMessageDeliveryRecipts!.autoSendMessageDeliveryRequests = true

但我没有进一步的想法,我该如何进一步处理以检查消息状态?

2) 如何像 whatsapp 那样获取未读消息数? 为了获取最近的消息,我在核心数据对象下面使用了 XMPPMessageArchiving_Contact_CoreDataObject

其他存档代码

self.xmppMessageArchivingStorage = XMPPMessageArchivingCoreDataStorage.sharedInstance();
self.xmppMessageArchiving = XMPPMessageArchiving(messageArchivingStorage: xmppMessageArchivingStorage);
self.xmppMessageArchiving!.clientSideMessageArchivingOnly = true;

但让我知道如何获取您阅读的消息数或帮助完整的代码片段?

我已经检查了下面的堆栈链接:

1) How to get the message delivery status using XMPP framework

2) Need assistance regarding using the xep-0184

3) How to get the message read/unread/report in xmpp framework

服务器:ejabber

最佳答案

XMPP 提供“流管理” 以了解消息是否已传送到 XMPP 服务器。

为此,您必须注册并激活它。这是代码。

// Stream Management 
func configureStreamManagement() {
let xmppSMMS = XMPPStreamManagementMemoryStorage()
xmppStreamManagement = XMPPStreamManagement(storage: xmppSMMS, dispatchQueue: DispatchQueue.main)
xmppStreamManagement.addDelegate(self, delegateQueue: DispatchQueue.main)
xmppStreamManagement.activate(xmppStream)
xmppStreamManagement.autoResume = true
xmppStreamManagement.ackResponseDelay = 0.2
xmppStreamManagement.requestAck()
xmppStreamManagement.automaticallyRequestAcks(afterStanzaCount: 1, orTimeout: 10)
xmppStreamManagement.automaticallySendAcks(afterStanzaCount: 1, orTimeout: 10)
xmppStreamManagement.enable(withResumption: true, maxTimeout: 0)
xmppStreamManagement.sendAck()
xmppStream.register(xmppStreamManagement)
}

认证成功后调用该方法

func xmppStreamDidAuthenticate(_ sender: XMPPStream!) {
print("Stream: Authenticated")
configureStreamManagement()
}

使用“XMPPStreamManagementDelegate”您可以获得传送到 XMPP 服务器的消息 ID。

func xmppStreamManagement(_ sender: XMPPStreamManagement!, didReceiveAckForStanzaIds stanzaIds: [Any]!) {
if let messageIds = stanzaIds as? [String] {
for id in messageIds {
print("Message is delivered to xmpp server: \(id)")
// TODO: Custom code goes here to change the message status
}
}
}

正如您在上面提到的,下面的代码将自动发送客户端的已交付回执,这意味着消息已交付给客户端。

self.xmppMessageDeliveryRecipts = XMPPMessageDeliveryReceipts(dispatchQueue: DispatchQueue.main)
self.xmppMessageDeliveryRecipts!.autoSendMessageDeliveryReceipts = true
self.xmppMessageDeliveryRecipts!.autoSendMessageDeliveryRequests = true

在“XMPPStreamDelegate”中,当消息被传送到客户端时,您将收到回执消息。

func xmppStream(_ sender: XMPPStream!, didReceive message: XMPPMessage!) {
print("Message From: \(message.from().user)")
print("Message Body: \(message.body())")
print("Message is delivered to client -: \(message.receiptResponseID())")
// TODO: Compare receiptResponseID with sent message's id.
}

关于ios - 如何在 XMPP iOS 中获取消息传递、已读、失败和未读消息数? ( swift 3.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45570136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com