问题
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