i am developing chat app in that i have stuck in two scenario.
1) How to get message status like delivered ,seen etc.. I have done following things :
XMPP provides 'Stream Management' to know whether message is delivered to XMPP server or not.
For that you have to register and activate it. Here is the code.
// 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)
}
Call this method after authentication is successful.
func xmppStreamDidAuthenticate(_ sender: XMPPStream!) {
print("Stream: Authenticated")
configureStreamManagement()
}
Using the 'XMPPStreamManagementDelegate' you can get the message ids which are delivered to XMPP server.
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
}
}
}
As you have mentioned above, below code will automatically send delivered receipts of client, which means message is delivered to client.
self.xmppMessageDeliveryRecipts = XMPPMessageDeliveryReceipts(dispatchQueue: DispatchQueue.main)
self.xmppMessageDeliveryRecipts!.autoSendMessageDeliveryReceipts = true
self.xmppMessageDeliveryRecipts!.autoSendMessageDeliveryRequests = true
In 'XMPPStreamDelegate' when message will be delivered to client you will get the receipt message.
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.
}