I have a recipient picker view. But I want to display only contacts that have a phone number before I pick one.
This is how I get the modal view:
-(void)messageWillShowRecipientPicker{
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
NSArray *displayedItems =
[NSArray arrayWithObject:[NSNumber
numberWithInt:kABPersonPhoneProperty]];
picker.displayedProperties = displayedItems;
// Show the picker
[self presentModalViewController:picker animated:YES];
[picker release];
}
Any idea how to do that?
Just did this my iPhone5S & it worked - Go to contacts - select groups - Under Exchange or your email account simply select contacts & turn off suggested contacts - All email only contacts unless saved that way as a contact should go off. Show activity on this post.
In addition, the Android app lets you organize your contacts more efficiently. Tap your avatar and go to Contacts app settings—under Display and Edit contacts, you'll be able to sort contacts by first name or last name, or to show or hide phonetic names.
I tested this out, should work. Might have to tweak it ^-^
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *allContacts = [(NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook)autorelease];
for (int i =0; i < allContacts.count; i++) {
ABRecordRef person = [allContacts objectAtIndex:i];
if (person != nil) {
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
if (ABMultiValueGetCount(phones) == 0) {
CFErrorRef error = nil;
ABAddressBookRemoveRecord(addressBook, person, &error);
NSLog(@"Removing %@",(NSString *)ABRecordCopyCompositeName(person));
}
CFRelease(phones);
}
}
CFErrorRef saveError = nil;
ABAddressBookSave(addressBook, &saveError);
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.addressBook = addressBook;
NSArray *displayedItems =
[NSArray arrayWithObject:[NSNumber
numberWithInt:kABPersonPhoneProperty]];
picker.displayedProperties = displayedItems;
// Show the picker
[self presentModalViewController:picker animated:YES];
CFRelease(addressBook);
You can use NSPredicate
to filter the data, but you may need to make a proxy object to deal with the AddressBook, or a Protocol.
Check out https://github.com/erica/ABContactHelper/blob/master/ABContactsHelper.m for an example of a Protocol for AddressBook and Apple's Predicate information here http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Predicates/Articles/pUsing.html and here http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSPredicate_Class/Reference/NSPredicate.html
Cheers and good luck! (^_^)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With