gpt4 book ai didi

ios - 通过 CNContactViewController 显示时,联系人缺少一些必需的键描述符

转载 作者:搜寻专家 更新时间:2023-10-31 22:32:59 24 4
gpt4 key购买 nike

尝试在给定的 tableView 中显示带有预建 UI 的联系人,当用户选择要显示的联系人时出现以下错误:

CNPropertyNotFetchedException', reason: 'Contact 0x7fded8ee6f40 is missing some of the required key descriptors: [CNContactViewController descriptorForRequiredKeys]>

我已经尝试用这个方法解决了:Contact is missing some of the required key descriptors in ios

所以我的联系人数组创建如下:

  func searchContactDataBaseOnName(name: String) {
results.removeAll()

let predicate = CNContact.predicateForContactsMatchingName(name)
//Fetch Contacts Information like givenName and familyName
let keysToFetch = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactViewController.descriptorForRequiredKeys()]

let store = CNContactStore()
do {
let contacts = try store.unifiedContactsMatchingPredicate(predicate,
keysToFetch: keysToFetch)
for contact in contacts {
self.results.append(contact)
}
tableContacts.reloadData()
}
catch{
print("Can't Search Contact Data")
}
}

当用户点击行索引时,我试图通过这样做来显示:

func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {

let viewControllerforContact = CNContactViewController(forContact: results[indexPath.row])
viewControllerforContact.contactStore = self.contactStore
viewControllerforContact.delegate = self

self.navigationController?.pushViewController(viewControllerforContact,animated:true)
}

关于如何解决的任何想法?似乎我仍然缺少将 descriptorForRequiredKeys 传递给数组“Results”……也许吧?

最佳答案

正在获取所需的键并将它们存储在您调用的结果变量中,所以我不知道原因。您可以使用所需的 key 重新获取联系人以解决错误:

var contact = results[indexPath.row]    
if !contact.areKeysAvailable([CNContactViewController.descriptorForRequiredKeys()]) {
do {
contact = try self.contactStore.unifiedContactWithIdentifier(contact.identifier, keysToFetch: [CNContactViewController.descriptorForRequiredKeys()])
}
catch { }
}
let viewControllerforContact = CNContactViewController(forContact: contact)

关于ios - 通过 CNContactViewController 显示时,联系人缺少一些必需的键描述符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35588194/

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