尝试在Xcode 10.1中使用Swift从macOS联系人获取联系人列表。我收到路径错误。
我正在使用推荐的方法,并且已在Info.plist中包含了隐私密钥。
func getAllContacts() {
let status = CNContactStore.authorizationStatus(for: CNEntityType.contacts) as CNAuthorizationStatus
print(status)
// if status == CNAuthorizationStatus.denied {
// showAccessContactsDeniedAlert()
// return
// }
let contactStore = CNContactStore()
let keysToFetch = [CNContactGivenNameKey, CNContactFamilyNameKey, CNPostalAddressStreetKey, CNPostalAddressCityKey, CNContactPhoneNumbersKey]
let request = CNContactFetchRequest(keysToFetch:keysToFetch as [CNKeyDescriptor])
do {
try contactStore.enumerateContacts(with: request, usingBlock: { (contact:CNContact, stop:UnsafeMutablePointer<ObjCBool>) -> Void in
print("\(contact.familyName) \(contact.givenName) ")
})
} catch {
//catch
}
这就是我得到的:
2019-05-13 23:54:10.586962 + 0200显示客户端[2324:83437] [默认]无法加载Info.plist异常(eGPUOverrides) CNAuthorizationStatus
2019-05-13 23:54:30.347100 + 0200显示客户端[2324:83437]无法获取地址簿锁定文件夹的真实路径:F_GETPATH的open()失败。
2019-05-13 23:54:30.347101 + 0200显示客户端[2324:83437]无法打开文件锁:{递归计数= 0,名称=无},fileDescriptor = -1>错误域= NSPOSIXErrorDomain代码= 14“错误地址” UserInfo = {ABFileDescriptor = -1}