iOS block user using XEP-0191

∥☆過路亽.° 提交于 2019-12-25 06:04:02

问题


I am developing chat application in iOS and using openfire xmpp server? I am trying to block the user using XEP-0191: Blocking Command but getting error in result.

error xmlns="jabber:client" type="cancel" code="503" service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"


回答1:


As i know openfier does not support XEP-0191 for block user. you need to implement XEP-0016 privacy list. so you have to create privacylist using this method.

- (void)setListWithName:(NSString *)privacyListName items:(NSArray *)items fromUser:(NSString *)user

and you can make it active with below method

- (void)setActiveListName:(NSString *)privacyListName;

and please refer

How to block friend with xmpp in iOS?

For more detail Regarding privacy list please follow

XEP-0016




回答2:


This works for me.

XMPPPrivacy  * xmppPrivacy =[[XMPPPrivacy alloc] initWithDispatchQueue:dispatch_get_main_queue()];
[xmppPrivacy activate:[XmppGlobalClass sharedInstance].xmppStream];
[xmppPrivacy addDelegate:self delegateQueue:dispatch_get_main_queue()];

NSMutableArray * arraypriv = [[NSMutableArray alloc]init];


NSMutableDictionary * privdict = [[NSMutableDictionary alloc] init];
[privdict setValue:@"deny" forKey:@"action"];
[privdict setValue:jid forKey:@"jid"];
[arraypriv addObject:privdict];

NSXMLElement *privacyElement;

NSMutableArray *arrayPrivacy = [[NSMutableArray alloc] init];


    privacyElement = [XMPPPrivacy privacyItemWithType:@"jid" 
    value:[NSString stringWithFormat:@"%@@%@",[arraypriv 
    valueForKey:@"jid"],domainName] action:[NSString stringWithFormat:@"%@",[arraypriv valueForKey:@"action"]] order:0];
    [arrayPrivacy addObject:privacyElement];



[XMPPPrivacy blockIQs:privacyElement];
[XMPPPrivacy blockMessages:privacyElement];
[XMPPPrivacy blockPresenceIn:privacyElement];
[XMPPPrivacy blockPresenceOut:privacyElement];
[xmppPrivacy setListWithName:@"public" items:arrayPrivacy];
[xmppPrivacy setActiveListName:@"public"];

Then you will receive the blocked user list in the delegate method (In XEP-0016) ,

- (void)xmppPrivacy:(XMPPPrivacy *)sender didReceiveListWithName:(NSString *)name items:(NSArray *)items;


来源:https://stackoverflow.com/questions/33038630/ios-block-user-using-xep-0191

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!