Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving Archived messages from XMPP server in ios

Tags:

ios

archive

xmpp

I am integrating XMPP functionality in my ios app and i came across a problem i cannot solve. The problem is i cannot get archived messages from the server. My client is able to log in and i have tested several service calls (send, receive messages, getting info about a user) with success.

Upon sending

<iq type='get' id='pref1'>
  <pref xmlns='urn:xmpp:archive'/>
</iq>

The response is

SEND: <iq type="get"><pref xmlns="urn:xmpp:archive"/></iq>

RECV: <iq xmlns="jabber:client" type="error" to="1@iis2/ae76edc"><error code="501"    
type="cancel"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-
stanzas"/</error></iq>

The server administrator is able to see the archived messages, as he activated archiving.

Must something be done server or client side in order to achieve this functionality? Could it be that seeing old messages and the server actually implementing and supporting XEP-0136, are two different things?

like image 680
Simon Avatar asked Jan 11 '13 13:01

Simon


1 Answers

If you want fetch from server means use this code

  internal var xmppMAM: XMPPMessageArchiveManagement?

func setupXMPPMam(){
    xmppMAM = XMPPMessageArchiveManagement.init()
    xmppMAM?.addDelegate(self, delegateQueue: .global(qos: .background))
    // stream is XMPPStream
    xmppMAM?.activate(stream)
}

call the setupMam function once XMPP connect

  func retrieveArchiveMessage(){
    let set = XMPPResultSet(max: totalCount)
    xmppMAM?.retrieveMessageArchive(at: XMPPJID(string: user), withFields: nil, with: set)
  }

 func xmppStream(_ sender: XMPPStream, willReceive message: XMPPMessage) -> XMPPMessage? {
    if let forwardedMessage = message.mamResult?.forwardedMessage{
      debugPrint(forwardedMessage)
      return message
    }
  }

if you using Robbiehanson framework above code is working perfectly for fetch value from server.

I hope this article is useful for you @Akash Thakkar

like image 164
Abishek Thangaraj Avatar answered Nov 14 '22 20:11

Abishek Thangaraj