Why XMPP function returns nothing?

Orkhan Alizade

I found in the documentation this:

<iq type='get' id='2'>
    <query xmlns='jabber:iq:roster'/>

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


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


extension OneRoster: XMPPStreamDelegate {
    public func xmppStream(sender: XMPPStream, didReceiveIQ ip: XMPPIQ) -> Bool {
        return false

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at


Login to comment