Reputation: 7549
I found in the documentation this:
<iq type='get' id='2'>
<query xmlns='jabber:iq:roster'/>
</iq>
And write it in Swift as:
public class func getGroups() {
var xmppStream: XMPPStream?
let iq: DDXMLElement = DDXMLElement.elementWithName("iq") as! DDXMLElement
iq.addAttributeWithName("type", stringValue: "get")
iq.addAttributeWithName("id", stringValue: "2")
let query: DDXMLElement = DDXMLElement(name: "query", xmlns: "jabber:iq:roster") as! DDXMLElement
iq.addChild(query)
xmppStream?.sendElement(iq)
}
And when I run it from my ViewController as:
override func viewDidLoad(animated: Bool) {
print("Group list: \(getGroups())")
}
it returns me empty value, just Group list:
.
My question is, how can I run my function properly and get the result, because when I run my XMPP <iq>
snippet in my server, it returns me value.
UPDATE You can write or correct my code even in Objective C
UPDATE
extension OneRoster: XMPPStreamDelegate {
public func xmppStream(sender: XMPPStream, didReceiveIQ ip: XMPPIQ) -> Bool {
return false
}
}
Upvotes: 0
Views: 227
Reputation: 5266
You are trying to reinvent XMPPRoster
module bundled with XMPPFramework
: just instantiate it and activate
on your XMPPStream instance and it will automatically sync your roster and groups. iPhoneXMPP
example show you roster with groups backed up by this module.
Upvotes: 1
Reputation: 6954
xmppStream?.sendElement(iq)
is like a request you make to server, so it wont be instant. You need to wait for delegate like 'didReceiveIQ:' to be called and there you will get response.
Dig this delegate and I am sure you will be able to get data as expected.
Upvotes: 1