我已经在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)
}
答案 0 :(得分:1)
您需要使用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){
}
}
}