0

我想在创建新的 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];
4

1 回答 1

0

在头文件 CNContactViewController.h 中,有一条注释说:“编辑联系人时所有属性都可见”。所以我想为新联系人设置显示属性键不会改变任何东西,因为它将在编辑模式下显示。

于 2016-08-29T10:08:30.283 回答