在 ios 中从 XMPP 服务器检索存档消息 [英] Retrieving Archived messages from XMPP server in ios

查看:22
本文介绍了在 ios 中从 XMPP 服务器检索存档消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的 ios 应用程序中集成 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.

发送后

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

回复是

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.

为了实现这个功能,必须在服务器端或客户端做些什么吗?会不会看到旧消息和服务器实际实现和支持 XEP-0136,是两件不同的事情?

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?

推荐答案

如果你想从服务器获取,就使用这个代码

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)
}

XMPP 连接后调用 setupMam 函数

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
    }
  }

如果您使用 Robbiehanson 框架,上面的代码可以完美地从服务器获取值.

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

希望这篇文章对你有用@Akash Thakkar

I hope this article is useful for you @Akash Thakkar

这篇关于在 ios 中从 XMPP 服务器检索存档消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆