I would like to show only a limited number of keys whilst creating a new CNContact (leveraging the viewControllerForNewContact method). However, despite the various values for the keys to fetch that I have tried, I still keep getting the entire universe of settable values. How can we limit the keys that are shown for new contacts?
This seems to be working fine for existing contacts, but somehow not for new contacts...
Below is my code so far...
CNMutableContact *newContact = [[CNMutableContact alloc] init];
// NSArray *keysToFetch = @[CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactEmailAddressesKey, CNContactImageDataKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName], [CNContactViewController descriptorForRequiredKeys]];
// NSArray *keysToFetch = @[[CNContactViewController descriptorForRequiredKeys]];
// NSArray *keysToFetch = @[CNContactGivenNameKey, [CNContactViewController descriptorForRequiredKeys]];
// NSArray *keysToFetch = @[CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName],[CNContactViewController descriptorForRequiredKeys]];
// NSArray *keysToFetch = @[[CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName], CNContactEmailAddressesKey];
NSArray *keysToFetch = @[CNContactGivenNameKey, CNContactPhoneNumbersKey];
CNContactViewController *newContactViewController = [CNContactViewController viewControllerForNewContact:newContact];
newContactViewController.delegate = self;
newContactViewController.allowsActions = YES;
newContactViewController.allowsEditing = YES;
newContactViewController.displayedPropertyKeys = keysToFetch;
UINavigationController *newContactNavViewController = [[UINavigationController alloc] initWithRootViewController:newContactViewController];
newContactNavViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:newContactNavViewController animated:YES completion:nil];