haresh haresh - 1 year ago 104
iOS Question

How to block a user in QuickBlox?

I am creating a chat based Application on

Framework, I want to have a block functionality in the App. I read out some of documents like XMPP and
. But did not got any help Out of that.

There is some logic of maintaining
for not to allow other user send message and block it but I didn't got succeed with it.

This is a code snippet how I am maintaining the Privacy List.

  1. Get the privacy list with Name
    in method of chat did login

    [[QBChat instance] retrievePrivacyListWithName:@"public"];

    so if there is already created privacy list named
    will fetch it in delegate method

    - (void)chatDidReceivePrivacyList:(QBPrivacyList *)privacyList{
    NSLog(@"chatDidReceivePrivacyList: %@", privacyList);
    _blockPrivacyList = privacyList; // Save its instance for further add more users in list

    // response is

    [PrivacyList name: public]items:("type: USER_ID valueForType: 2075213 action: deny"

  2. This is how add another member in privacy list

    - (void)blockUserWithQBId:(NSUInteger)qbID

    QBPrivacyItem *item = [[QBPrivacyItem alloc] initWithType:USER_ID valueForType:qbID action:DENY];

    if (_blockPrivacyList) {
    [_blockPrivacyList addObject:item]; // add new user if already privacy list is there
    _blockPrivacyList = [[QBPrivacyList alloc] initWithName:@"public" items:@[item]]; // create new privacy list if not before created

    [[QBChat instance] setPrivacyList:_blockPrivacyList];


    And all the delegate methods works perfectly creates and adds member in privacy list.

    - (void)chatDidSetPrivacyListWithName:(NSString *)name{
    NSLog(@"chatDidSetPrivacyListWithName %@", name);
    [[QBChat instance] setDefaultPrivacyListWithName:name]; // set it as default privacy list

  3. I get this privacy list perfectly even i kill the app or Reinstall it for same user.
    so my privacy list code is working perfectly

But some how the other members in my
privacy list can send me message.
According to the documents from this http://quickblox.com/developers/SimpleSample-chat_users-ios#Contact_list it should give the error like

"error:Error Domain=com.quickblox.chat Code=503 "Service not available."

So if all privacy list works perfectly then how can my blocked users could send me messages?

I had worked with
the same issue exist there also if you can give
logic that will also work as
actually uses

Any suggestions for this?

Answer Source

Finally found its solution. The flow and logic i had written in my question was perfect. I was just remaining with the one small function to activate the privacy list. Dont know why QuickBlox has not written that function call in their demos.

    [[QBChat instance] setActivePrivacyListWithName:@"public"];

Same in XMPP we need to maintain the Privacy list and activate single privacy at one time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download