PubNub Prevent Receiving Your Own Messages Using Objective-C


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: