如何在iOS中使用xmpp阻止朋友? [英] How to block friend with xmpp in iOS?

查看:52
本文介绍了如何在iOS中使用xmpp阻止朋友?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发聊天应用程序.我想屏蔽朋友.我正在使用 xmpp 框架的 XEP-0016 扩展.

I am working on the chat application. I want to block friend. I am using XEP-0016 extensions of xmpp framework.

这是我的代码..

- (void)setupXMPPPrivacy
{
    NSLog((@"%s [Line %d] "), __PRETTY_FUNCTION__, __LINE__);
    //Init XMPPPrivacy List
    //xmppPrivacy = [[XMPPPrivacy alloc] init];
    xmppPrivacy = [[XMPPPrivacy alloc] initWithDispatchQueue:dispatch_get_main_queue()];
    //Activate xmpp modules
    [xmppPrivacy activate:xmppStream];
    //Delegate XMPPPrivacy
    [xmppPrivacy addDelegate:self delegateQueue:dispatch_get_main_queue()];
}


- (void)privacyBlock:(XMPPJID *)jid
{
    NSXMLElement *privacyElement = [XMPPPrivacy privacyItemWithType:@"jid" value:jid.bare action:@"deny" order:1];
    [XMPPPrivacy blockIQs:privacyElement];
    [XMPPPrivacy blockMessages:privacyElement];
    [XMPPPrivacy blockPresenceIn:privacyElement];
    [XMPPPrivacy blockPresenceOut:privacyElement]; 
    NSLog(@"-------> PRIVACY ELEMENT: %@", privacyElement);

    NSArray *arrayPrivacy = [[NSArray alloc] initWithObjects:privacyElement, nil];
    [xmppPrivacy setListWithName:@"public" items:arrayPrivacy];
}

但是,这是行不通的.我做错了什么?

But, this is not working. What am I doing wrong?

请帮忙.谢谢.

推荐答案

我也遇到了同样的问题.第一个问题是 UUID 生成器,它返回 nil.但是在 iOS 5 中添加了 NSUUID 类.所以使用 [[NSUUID UUID] UUIDString] 我解决了这个问题.第二个问题是我的大错.我初始化了 xmmpStram 并请求阻止,但打开流需要一些时间.所以,我在打开流之前请求.

I had the same trouble. First problem was UUID generator, it returned nil. But in iOS 5 added NSUUID class. So using [[NSUUID UUID] UUIDString] I solved this problem. Second problem was my big mistake. I initialized xmmpStram and did request to block, but opening stream takes some time.So, I requested before opening a stream.

这篇关于如何在iOS中使用xmpp阻止朋友?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆