Why XMPP function returns nothing?

Orkhan Alizade

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
    }
}
vitalyster

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
0

Comments

0 comments
Login to comment

Related