How to get chat history using XMPPFramework in iOS

555 Views Asked by At

I have used XMPPFramework for one of my Chat application. I got success with the realtime chatting using this library. But when I try to fetch the history for one to one user chat and also for the group chat, then I didn't get results.

I am using the below code to fetch chat history.

 let detxTag:XMLElement = XMLElement(name: "message")
 detxTag.addAttribute(withName: "id", stringValue: "[email protected]")
 detxTag.addAttribute(withName: "type", stringValue: "chat")
 detxTag.addChild(detxTag)

After this, I reviewed the same issue created at the mentioned repository and found the below code as a solution to get chat history.

let mam = XMPPMessageArchiveManagement()
mam.activate(xmppStream)
mam.addDelegate( ... )

let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"

var fields = [DDXMLElement]()
fields.append(XMPPMessageArchiveManagement.field(withVar: "start", type: "text-single", andValue: formatter.string(from: startDate)))

mam.resultAutomaticPagingPageSize = 150
mam.retrieveMessageArchive(at: room.roomJID, withFields: fields, with: nil)

[Referernce fo above code]

But, still, I didn't get proper success with this. Can anyone please guide me what can be changed need update to have chat history?

0

There are 0 best solutions below