gpt4 book ai didi

ios - Contact 在 ios 中缺少一些必需的键描述符

转载 作者:可可西里 更新时间:2023-11-01 03:24:48 25 4
gpt4 key购买 nike

我已经使用以下方法检索了所有联系人

- (void)getAllContacts:(void(^)(NSArray *array))handler
{
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];

if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusDenied)
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"This app previously was refused permissions to contacts; Please go to settings and grant permission to this app so it can use contacts" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:TRUE completion:nil];
return;
}

CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {

// make sure the user granted us access
if (!granted)
{
dispatch_async(dispatch_get_main_queue(), ^{
// user didn't grant access;
// so, again, tell user here why app needs permissions in order to do it's job;
// this is dispatched to the main queue because this request could be running on background thread
});
return;
}

// build array of contacts
NSMutableArray *contacts = [NSMutableArray array];

NSError *fetchError;
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]]];

BOOL success = [store enumerateContactsWithFetchRequest:request error:&fetchError usingBlock:^(CNContact *contact, BOOL *stop) {

[contacts addObject:contact];
}];

if (!success)
{
NSLog(@"error = %@", fetchError);
return;
}
handler((NSArray *)contacts);
}];

联系人列在表格 View 中。现在我正在尝试从 `` 中选择特定的联系人,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CNContact *contact = [arrContacts objectAtIndex:indexPath.row];
NSArray *keys = @[CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]];
CNContactViewController *contactController = [CNContactViewController viewControllerForContact:contact];
contactController.delegate = self;
contactController.allowsEditing = YES;
contactController.allowsActions = YES;
contactController.displayedPropertyKeys = keys;
[self.navigationController pushViewController:contactController animated:TRUE];
}

但是它说

Contact 0x7fc732654530 is missing some of the required key descriptors

有知道的请帮我解决一下。谢谢。

最佳答案

在 keysToFetch 数组的末尾添加“CNContactViewController.descriptorForRequiredKeys”。

在我这样做之后为我工作。

示例:

NSArray *keysToFetch = @[CNContactIdentifierKey, CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactImageDataAvailableKey, CNContactImageDataKey, CNContactViewController.descriptorForRequiredKeys];

关于ios - Contact 在 ios 中缺少一些必需的键描述符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33391950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com