0

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];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
vikram17000
  • 453
  • 5
  • 18

1 Answers1

0

In the header file CNContactViewController.h, there is a note saying: “All properties are visible when editing the contact”. So I guess it doesn't change anything to set displayedPropertyKeys for a new contact, since it will be displayed in editing mode.

Guillaume
  • 4,331
  • 2
  • 28
  • 31