【发布时间】:2016-12-24 01:53:01
【问题描述】:
所以我的这段代码可以正常工作,但前提是您在 predicateForContacts 参数中指定了名称。
func retrieveContactsWithStore(store: CNContactStore) {
do {
let predicate = CNContact.predicateForContacts(matchingName: "John")
let keysToFetch = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactPhoneNumbersKey] as [Any]
let contacts = try store.unifiedContacts(matching: predicate, keysToFetch: keysToFetch as! [CNKeyDescriptor])
self.objects = contacts
DispatchQueue.main.async(execute: { () -> Void in
self.myTableView.reloadData()
})
} catch {
print(error)
}
}
我想检索地址簿上列出的所有人员的姓名。
【问题讨论】:
-
阅读文档! developer.apple.com/reference/contacts/cncontactstore/… 注意开头的句子:“To fetch all contacts...”
标签: swift swift3 cncontact cncontactstore