【问题标题】:How to retrieve the last sent message from myself in XMPP using xmppframework?如何使用 xmppframework 在 XMPP 中检索我自己发送的最后一条消息?
【发布时间】:2018-07-14 06:10:09
【问题描述】:

我想检索我在 XMPP 中发送给某人的最后一条消息。
我已经编写了这段代码,但它会获取所有发送的消息:

let query = try? XMLElement(xmlString: "<query xmlns='urn:xmpp:mam:2'/>")
let iq = XMLElement.element(withName: "iq") as? XMLElement
iq?.addAttribute(withName: "type", stringValue: "set")
iq?.addAttribute(withName: "from", stringValue: "f.talebi@x.ir")
iq?.addAttribute(withName: "max", stringValue: "1")
iq?.addAttribute(withName: "id", stringValue: "GetLastUserMessage")


if let aQuery = query {
     iq?.addChild(aQuery)
}

xmppStream.send(iq!)

【问题讨论】:

    标签: ios swift xmppframework


    【解决方案1】:

    首先你应该有 xmppMessageArchiveManagement 模块:

    var xmppMAM: XMPPMessageArchiveManagement!

    然后激活它

    xmppMAM.activate(xmppStream)

    之后就可以使用xmppMessageArchiveManagementDelegate的协议功能了

    extension someClass: XMPPMessageArchiveManagementDelegate { func xmppMessageArchiveManagement(_ xmppMessageArchiveManagement: XMPPMessageArchiveManagement, didReceiveMAMMessage message: XMPPMessage) { } func xmppMessageArchiveManagement(_ xmppMessageArchiveManagement: XMPPMessageArchiveManagement, didFinishReceivingMessagesWith resultSet: XMPPResultSet) { } }

    现在您可以创建数据包并发送它们,以上两个函数将捕获服务器的数据包: 注意:您应该使用 mam:1 而不是 mam:2 并使用 messageArchiveManagement 进行所有检索任务。示例:检索您的最后一条消息构建此数据包并使用 mam 发送它。

    `let value = DDXMLElement(name: "value", stringValue: youJid)
     let child = DDXMLElement(name: "field")
     child.addChild(value)
     child.addAttribute(withName: "var", stringValue: "with")
     let set = XMPPResultSet(max: 1, before: "")
     xmppMam.retrieveMessageArchive(at: nil, withFields: [child], with: set)`
    

    【讨论】:

    • 谢谢。但我没有 XmppMessageArchiveModule
    猜你喜欢
    • 2011-09-29
    • 1970-01-01
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 2011-07-05
    • 2012-06-21
    相关资源
    最近更新 更多