【发布时间】:2015-07-29 16:49:18
【问题描述】:
如何在目标 C 中以编程方式从 openfire 服务器获取所有朋友,我正在使用 XMPP 聊天功能框架。
【问题讨论】:
标签: xmpp chat objective-c-blocks openfire
如何在目标 C 中以编程方式从 openfire 服务器获取所有朋友,我正在使用 XMPP 聊天功能框架。
【问题讨论】:
标签: xmpp chat objective-c-blocks openfire
这是一个获取朋友的函数。
在下面的函数中添加您的主机名。
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)
}
您将在委托方法中获得列表。
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)
}
}
}
}
您可以查看我的此链接,了解 XMPP 连接和不同的代表。
【讨论】:
在 iOS 中,您可以在 xmpp 中使用以下功能轻松获取群组成员/朋友
- (void)xmppRoom:(XMPPRoom *)sender didFetchModeratorsList:(NSArray *)items
【讨论】: