我想在创建新的 CNContact 时只显示有限数量的键(利用 viewControllerForNewContact 方法)。然而,尽管我已经尝试了各种获取键的值,但我仍然不断获得整个可设置值的范围。我们如何限制为新联系人显示的键?
这似乎适用于现有联系人,但不知何故不适用于新联系人......
以下是我到目前为止的代码...
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];