gpt4 book ai didi

ios - 在 Swift 3.0 中使用 XMPP 阻止和取消阻止用户

转载 作者:搜寻专家 更新时间:2023-11-01 07:07:50 25 4
gpt4 key购买 nike

我查看了很多有关在 Swift 中使用 XMPP 阻止和取消阻止用户的博客和网站。但是,没有一个例子对我有用。任何有代码段的人请与我分享。谢谢。

func blockUser(userJID: String) {
let privacyList = XMPPPrivacy(dispatchQueue: DispatchQueue.main)
privacyList?.activate(xmppStream)
privacyList?.addDelegate(self, delegateQueue: DispatchQueue.main)

let privacyElement = XMPPPrivacy.privacyItem(withType: "jid", value: userJID, action: "deny", order: 0)
XMPPPrivacy.blockIQs(privacyElement)
XMPPPrivacy.blockMessages(privacyElement)
XMPPPrivacy.blockPresence(in: privacyElement)
}

最佳答案

您需要使用 XEP 0191用于阻止功能。

代码( swift 3.0):

     //Block / Unblock User

var xmppBlocking: XMPPBlocking?

添加阻止用户和取消阻止用户

//Blocking Managment
self.xmppBlocking = XMPPBlocking()
self.xmppBlocking!.autoRetrieveBlockingListItems = true
self.xmppBlocking!.autoClearBlockingListInfo = true;
self.xmppBlocking!.addDelegate(self, delegateQueue: DispatchQueue.main)
self.xmppBlocking!.activate(self.xmppStream)
self.xmppBlocking?.retrieveBlockingListItems()

xmppBlocking?.blockJID(user.jid)
xmppBlocking?.unblockJID(user.jid)



extension BlockListVC : XMPPBlockingDelegate{

public func xmppBlocking(_ sender: XMPPBlocking!, didBlockJID xmppJID: XMPPJID!){
//Successfully blocked
}

public func xmppBlocking(_ sender: XMPPBlocking!, didNotBlockJID xmppJID: XMPPJID!, error: Any!){
if(error is NSError){
//print error message
}
}

public func xmppBlocking(_ sender: XMPPBlocking!, didReceivedBlockingList blockingList: [Any]!) {
//Received blocked list in this delegate method
}

public func xmppBlocking(_ sender: XMPPBlocking!, didUnblockJID xmppJID: XMPPJID!) {

}

public func xmppBlocking(_ sender: XMPPBlocking!, didNotUnblockJID xmppJID: XMPPJID!, error: Any!) {
if(error is NSError){

}
}
}

关于ios - 在 Swift 3.0 中使用 XMPP 阻止和取消阻止用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47018610/

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