Get Friends list from openfire Server

送分小仙女□ 提交于 2019-12-23 06:39:07

问题


How to get all friends programmatically from openfire server in objective C, I am using XMPP Framework for chat Functionality.


回答1:


Here is a function to fetch friends.

Add your host name in below function.

func getList() {
  let query = try! XMLElement(xmlString: "<query xmlns='http://jabber.org/protocol/disco#items' node='all users'/>")
  let iq = XMPPIQ(type: "get", to: XMPPJID(string: "Your Host Name"), elementID: xmppStream.generateUUID(), child: query)
  iq?.addAttribute(withName: "id", stringValue: "get")
  xmppStream.send(iq)
}

You will get the list in delegate method.

extension YourClassName: XMPPRosterDelegate {

    func xmppRosterDidEndPopulating(_ sender: XMPPRoster!) {
        if let jids = xmppRoster.xmppRosterStorage.jids(for: xmppStream) as? [XMPPJID] {
            print("JIDS: \(String(describing: jids))")
            for item in jids {
                print(item.user)
            }
        }
    }
}

You can have a look at my this link for XMPP Connection and different delegates.

https://stackoverflow.com/a/50149977/2781720




回答2:


In iOS you can easily get Group members/friends using below function in xmpp

- (void)xmppRoom:(XMPPRoom *)sender didFetchModeratorsList:(NSArray *)items


来源:https://stackoverflow.com/questions/30298853/get-friends-list-from-openfire-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!