How to filter contacts using a set of phone numbers with CNContactPickerViewController?
<p>I try to filter some contacts from address book with a set of existing phone numbers. <code>CNContactPickerViewController</code> should disable selection of these contacts when they have matching phone number from existing phone numbers.</p>

<p>I need to use phone number as a filter because these phone number can be from other app platforms. And the service should not allow user to use contact with same phone number that is already existed. I don't want to create my own contact picker for just this quick action.</p>

<p>Here is what I've tried so far.</p>

<pre><code>NSArray&lt;CNPhoneNumber *&gt; *existingPhoneNumbers = @[@"1111", @"2222"];

CNContactPickerViewController *contactPicker = [[CNContactPickerViewController alloc] init];
contactPicker.delegate = self;
contactPicker.displayedPropertyKeys = @[CNContactNamePrefixKey,
                                        CNContactGivenNameKey,
                                        CNContactFamilyNameKey,
                                        CNContactOrganizationNameKey,
                                        CNContactPhoneNumbersKey];

NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"NOT (ANY phoneNumbers.value.stringValue IN %@)", existingPhoneNumbers];

contactPicker.predicateForEnablingContact = predicates;
</code></pre>

<p>Error message:</p>

<pre><code>[CNUI ERROR] Error when showing picker: Error Domain=CNErrorDomain Code=300 "(null)" UserInfo={CNValidationErrors=(
"Error Domain=CNErrorDomain Code=400 \"Invalid Predicate\" UserInfo={CNKeyPaths=(\n    \"phoneNumbers.value.stringValue\"\n), NSLocalizedDescription=Invalid Predicate, NSLocalizedFailureReason=The operation couldn't be completed because its predicate is invalid.}")}
</code></pre>

<p>With <code>SUBQUERY</code> it is still not working.</p>

<pre><code>NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"SUBQUERY(phoneNumbers, $CNLabeledValue,$CNLabeledValue.value.stringValue IN %@).@count == 0"];
</code></pre>

<p>Error message:</p>

<pre><code>[CNUI ERROR] Error when showing picker: Error Domain=CNErrorDomain Code=300 "(null)" UserInfo={CNValidationErrors=(
"Error Domain=CNErrorDomain Code=400 \"Invalid Predicate\" UserInfo={CNKeyPaths=(\n    \"value.stringValue\"\n), NSLocalizedDescription=Invalid Predicate, NSLocalizedFailureReason=The operation couldn't be completed because its predicate is invalid.}")}
</code></pre>

<p>Also tried with <code>predicateWithBlock:</code>. It doesn't support block-based predicate at all.</p>

<p>From <a href="https://developer.apple.com/videos/play/wwdc2015/223/" rel="nofollow">WWDC 2015 Introducing the Contacts Framework for iOS and OS X session</a>.
They said <code>predicateForEnablingContact</code> is evaluated on 'CNContact'. The document doesn't say that predicate must be from <code>CNContact+Predicates</code> like <code>CNContactFetchRequest</code> does.</p>