Получать архивные сообщения с сервера xmpp - Swift - PullRequest
0 голосов
/ 20 мая 2018

Я хочу получать сообщения с сервера 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>
...