从xmpp服务器获取存档消息 - Swift

时间:2018-05-20 06:30:12

标签: ios swift xmppframework

我想从xmpp服务器获取消息 我实施了一些想法,但两者都不起作用。

首先:

let iq = XMLElement.element(withName: "get_archive_user1") as? XMLElement
iq?.addAttribute(withName: "type", stringValue: "get")
iq?.addAttribute(withName: "id", stringValue: "get_archive_user1")

let query = try? XMLElement(xmlString: "<query xmlns='urn:xmpp:mam:1'/>")

iq?.addChild(query!)

let with = XMLElement(name: "with", stringValue: "fattaneh123@jabb3r.org")

let set = XMLElement(name: "set", xmlns: "http://jabber.org/protocol/rsm")
let max = XMLElement.element(withName: "max", stringValue: "100") as? XMLElement
let before = XMLElement.element(withName: "before") as? XMLElement
set.addChild(max!)
set.addChild(before!)

query?.addChild(with)
query?.addChild(set)

xmppStream.send(iq!)

上述代码未收到任何消息。

第二

var iq1 = XMLElement.element(withName: "iq") as? XMLElement
iq1?.addAttribute(withName: "type", stringValue: "get")
iq1?.addAttribute(withName: "id", stringValue: "pk1")
var retrieve = XMLElement(name: "retrieve", xmlns: "urn:xmpp:archive")
retrieve.addAttribute(withName: "with", stringValue: "fattaneh123@jabb3r.org")
var `set` = XMLElement(name: "set", xmlns: "http://jabber.org/protocol/rsm")
var max = XMLElement.element(withName: "max", stringValue: "100") as? XMLElement
iq1?.addChild(retrieve)
retrieve.addChild(`set`)
if let aMax = max {
    `set`.addChild(aMax)
}

xmppStream.send(iq1!)

输出

<iq xmlns="jabber:client" id="pk1" type="error" to="fattaneh1234@jabb3r.org/4b27ae0b-8c57-4185-ab27-09f721847911"><error type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></service-unavailable></error></iq>

0 个答案:

没有答案