HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了联系人缺少ios中的一些必需的密钥描述符大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用以下方法检索所有联系人
- (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,CNContactPhone@R_197_10793@ersKey,[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);
   }];

}

表格中列出了联系人.现在我试图从“中选择特定的联系方式,

- (void)tableView:(UITableView *)tableView didSELEctRowATindexPath:(NSIndexPath *)indexPath
{
    CNContact *contact = [arrContacts objectATindex:indexPath.row];
    NSArray *keys = @[CNContactIdentifierKey,[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];
}

但它说

如果有人知道,请帮我解决.谢谢.

解决方法

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

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

例:

NSArray *keysToFetch = @[CNContactIdentifierKey,CNContactGivenNameKey,CNContactFamilyNameKey,CNContactimageDataAvailableKey,CNContactViewController.descriptorForrequiredKeys];

大佬总结

以上是大佬教程为你收集整理的联系人缺少ios中的一些必需的密钥描述符全部内容,希望文章能够帮你解决联系人缺少ios中的一些必需的密钥描述符所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。