我是xmppframework的新手。我有一个快速的问题。是否有可能知道某个JID是否可用。换句话说,可以检查用户名是否已与特定帐户关联或注册。
答案 0 :(得分:1)
使用jabber搜索,是的,您可以搜索和查找具有特定jID或userName或...的用户
在这里,我创建了一个函数,该函数将一些jID作为参数,并将服务器对您的响应作为查询,在该查询中,如果有任何匹配项,则将包含包含具有匹配jID的用户的项
func xmppQueryForSearchPacket(forJID jid: String) {
let searchingServer = "search.something" //something must replace with your xmpp domain name
let query = DDXMLElement(name: "query", xmlns: "jabber:iq:search")
let x = DDXMLElement(name: "x", xmlns: "jabber:x:data")
x.addAttribute(withName: "type", stringValue: "submit")
let field1 = DDXMLElement(name: "field")
let value1 = DDXMLElement(name: "value", stringValue: "jabber:iq:search")
field1.addAttribute(withName: "type", stringValue: "hidden")
field1.addAttribute(withName: "var", stringValue: "FORM_TYPE")
field1.addChild(value1)
let field2 = DDXMLElement(name: "field")
let value2 = DDXMLElement(name: "value", stringValue: jid)
field2.addAttribute(withName: "type", stringValue: "text-single")
field2.addAttribute(withName: "var", stringValue: "search")
field2.addChild(value2)
//we just search in userNames
let field3 = DDXMLElement(name: "field")
let value3 = DDXMLElement(name: "value", stringValue: "1")
field3.addAttribute(withName: "type", stringValue: "boolean")
field3.addAttribute(withName: "var", stringValue: "Username")
field3.addChild(value3)
x.addChild(field1)
x.addChild(field2)
x.addChild(field3)
query.addChild(x)
let iq = XMPPIQ(iqType: .set, to: XMPPJID(string: searchingServer), elementID: XMPPStream.generateUUID, child: query)
XMPPStream.send(iq)
}
该数据包的答案将以查询形式出现,您可以像这样接收它:
extension yourClassName: XMPPStreamDelegate {
func xmppStream(_ sender: XMPPStream, didReceive iq: XMPPIQ) -> Bool {
let searchingServer = "search.something"
if iq.from?.bare != searchingServer {
return true
}
return false
}
}
有关更多信息,请阅读XEP-0055。