使用 Objective-C 防止接收自己的訊息

設定過濾器適用於你將從該特定客戶端訂閱的所有通道。此客戶端過濾器排除將此訂戶的 UUID 設定為發件人的 UUID 的郵件:

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

釋出郵件時,如果希望訂閱者端客戶端篩選器工作,則需要包含發件人的 UUID:

[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];
    }
}];

也可以看看: