Ios 大厦及;在Swift 3.0中使用XMPP取消阻止用户
我在Swift中使用XMPP为阻止和取消阻止用户查看了很多博客和网站。 但是,没有一个例子对我有效。 任何人有代码片段,请与我分享。 多谢各位Ios 大厦及;在Swift 3.0中使用XMPP取消阻止用户,ios,swift,xmpp,Ios,Swift,Xmpp,我在Swift中使用XMPP为阻止和取消阻止用户查看了很多博客和网站。 但是,没有一个例子对我有效。 任何人有代码片段,请与我分享。 多谢各位 func blockUser(userJID: String) { let privacyList = XMPPPrivacy(dispatchQueue: DispatchQueue.main) privacyList?.activate(xmppStream) privacyList?.addDelegate(self, del
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)
}
您需要使用用于阻塞功能
代码(Swift 3.0):
添加阻止用户和取消阻止用户
//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){
}
}
}
这完全取决于您的实现。所以,只要把你尝试过的东西贴出来就行了。此外,询问代码将使您的问题被否决,因为它是皱眉了。我已经张贴了一个问题的代码。现在你可以检查一下,让我知道我哪里出错了。
//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){
}
}
}