iOS-使用CNContactViewController的问题



在tableView列表中显示自定义UI的联系人,当选中联系跳转显示时崩溃并出现错误:

*** Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'Contact 0x101331a70 is missing some of the required key descriptors: (
    "<CNAggregateKeyDescriptor: 0x28276fa80: kind=+[CNContactContentViewController descriptorForRequiredKeys]>"
)'
terminating with uncaught exception of type NSException


联系人数组是:

@property(nonatomic,strong)NSMutableArray<CNContact *> * contactArray;


当选中其中一行索引时,我试图通过这样做来显示:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    CNContact * contact = [self.dataArray objectAtIndex:indexPath.row];

    CNContactViewController *vc = [CNContactViewController viewControllerForContact:contact];
    vc.delegate = self;
    vc.displayedPropertyKeys = @[CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey];
    [vc setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:vc animated:YES];
}

崩溃信息显示:缺少descriptorForRequiredKeys 传递给数组


解决方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    CNContact * contact = [self.dataArray objectAtIndex:indexPath.row];
    
    CNContactStore *store = [[CNContactStore alloc] init];
    NSError *error = nil;
    contact = [store unifiedContactWithIdentifier:contact.identifier
                            keysToFetch:@[[CNContactViewController descriptorForRequiredKeys]]
                                  error:&error];

    CNContactViewController *vc = [CNContactViewController viewControllerForContact:contact];
    vc.delegate = self;
    vc.displayedPropertyKeys = @[CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey];
    [vc setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:vc animated:YES];
}







问题2: [CNUI ERROR] Contact view delayed appearance timed out

弹出联系人列表,选中行索引显示联系人详情时,无反应。

[CNUI ERROR] Contact view delayed appearance timed out
[CNUI ERROR] Contact view delayed appearance timed out
[CNUI ERROR] Contact view delayed appearance timed out
......


代码:

// [选择联系人]
- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact {
    CNContactViewController *vc = [CNContactViewController viewControllerForContact:contact];
    vc.delegate = self;
    vc.displayedPropertyKeys = @[CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey];
    [self presentViewController: vc animated:YES completion:nil];
}


解决方法:

// [选择联系人]
- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact {
    CNContactViewController *vc = [CNContactViewController viewControllerForContact:contact];
    vc.delegate = self;
    vc.displayedPropertyKeys = @[CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey];
    
    //将vc包装进UINavigationController
    UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:vc];
    
    __weak SecondMethodViewController * weakSelf = self;
    
    //出现延迟:[CNUI ERROR] Contact view delayed appearance timed out
    //通知主线程刷新UI
    dispatch_async(dispatch_get_main_queue(), ^{
        [weakSelf presentViewController:navi animated:YES completion:nil];
    });
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容