Swift 如何在macOS中无误地访问联系人
正在尝试使用Xcode 10.1中的Swift从macOS联系人获取联系人列表。我得到一个路径错误 我正在使用推荐的方法,并已将隐私密钥包含在Info.plist中Swift 如何在macOS中无误地访问联系人,swift,macos,contacts,Swift,Macos,Contacts,正在尝试使用Xcode 10.1中的Swift从macOS联系人获取联系人列表。我得到一个路径错误 我正在使用推荐的方法,并已将隐私密钥包含在Info.plist中 func getAllContacts() { let status = CNContactStore.authorizationStatus(for: CNEntityType.contacts) as CNAuthorizationStatus print(status) // if status
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
}
func getAllContacts(){
让status=CNContactStore.authorizationStatus(对于:CNEntityType.contacts)作为CNAuthorizationStatus
打印(状态)
//如果状态==CNAuthorizationStatus.denied{
//showAccessContactsDeniedAlert()
//返回
// }
让contactStore=CNContactStore()
let keystefetch=[CNContactGivenNameKey,CNContactFamilyNameKey,CNPostalAddressStreetKey,CNPostalAddressCityKey,CNContactPhoneNumbersKey]
let request=CNContactFetchRequest(keystefetch:keystefetch作为[CNKeyDescriptor])
做{
尝试contactStore.enumerateContacts(with:request,usingBlock:{(contact:CNContact,stop:UnsafeMutablePointer)->在中无效
打印(\(contact.familyName)\(contact.givenName)\)
})
}抓住{
//抓住
}
以下是我得到的:
2019-05-13 23:54:10.586962+0200显示客户端[2324:83437][默认]无法加载Info.plist异常(eGPUOverrides)
CNAuthorizationStatus2019-05-13 23:54:30.347100+0200显示客户端[2324:83437]无法获取通讯簿锁定文件夹的实际路径:F_GETPATH的open()失败。
2019-05-13 23:54:30.347101+0200显示客户端[2324:83437]无法打开文件锁:{recursion count=0,name=nil},fileDescriptor=-1>Error Domain=NSPOSIXErrorDomain Code=14“坏地址”UserInfo={ABFileDescriptor=-1}
当我在选择“联系人”应用程序数据的情况下打开沙箱功能并再次关闭沙箱时,错误消失。