gpt4 book ai didi

ios - 如何检查用户 JID 是否已在 XMPPFrameWork 中使用

转载 作者:行者123 更新时间:2023-11-28 14:23:53 26 4
gpt4 key购买 nike

我是 xmppframework 的新手。我有一个快速的问题。是否有可能知道某个 JID 是否可用。换句话说,是否可以检查用户名是否已与特定帐户关联或注册。

最佳答案

使用 jabber 搜索是的,您可以搜索并找到具有特定 jID 或用户名或...的用户

在这里,我创建了一个函数,它将一些 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 .

关于ios - 如何检查用户 JID 是否已在 XMPPFrameWork 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51758226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com