PubNub Message Filtering Prevent Receiving Your Own Messages Using Objective-C

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Setting a filter applies to all channels that you will subscribe to from that particular client. This client filter excludes messages that have this subscriber's UUID set at the sender's UUID:

NSString *expression = [NSString stringWithFormat:@"(uuid != '%@'", 
                        self.client.currentConfiguration.uuid];
[self.client setFilterExpression:expression];

When publishing messages, you need to include the sender's UUID if you want the subscriber side client filter to work:

[self.client publish:@"message" toChannel:@"group-chat" 
        withMetadata:@{@"uuid": self.client.currentConfiguration.uuid} 
          completion:^(PNPublishStatus *status) {

    // Check whether request successfully completed or not.
    if (!status.isError) {    

        // Message successfully published to specified channel.
    }
    else {

        // Request processing failed. Handle message publish error. 
        // Check 'category' property to find out possible issue 
        // publish can be attempted again using: [status retry];
    }
}];

See also:



Got any PubNub Question?