gpt4 book ai didi

swift - CNContactStore 执行失败

转载 作者:行者123 更新时间:2023-11-28 07:30:38 27 4
gpt4 key购买 nike

我正在研究如何使用联系人框架,但是创建联系人的一些相当简单的代码失败并出现意外结果。这是我的代码:

    let Store = CNContactStore()
Store.requestAccess(for: .contacts, completionHandler:{ success, error in
if success {
let Contact = CNMutableContact()
Contact.givenName = "Dave"
Contact.familyName = "Nottage"
let SaveRequest = CNSaveRequest()
SaveRequest.add(Contact, toContainerWithIdentifier: nil)
do {
try Store.execute(SaveRequest)
print("Success")
}
catch let error as NSError {
print(error.localizedDescription)
}
} else {
print("No access")
}
})

..这是结果:

2019-02-22 10:30:56.050344+1030 ContactsTest[30329:25254955] [default] Unable to load Info.plist exceptions (eGPUOverrides)
2019-02-22 10:30:57.973724+1030 ContactsTest[30329:25254955] Could not get real path for Address Book lock folder: open() for F_GETPATH failed.
2019-02-22 10:30:57.973954+1030 ContactsTest[30329:25254955] Unable to open file lock: <ABProcessSharedLock: 0x600001752ac0: name=(null), lockFilePath=(null), localLock=<NSRecursiveLock: 0x600002914a80>{recursion count = 0, name = nil}, fileDescriptor=-1> Error Domain=NSPOSIXErrorDomain Code=14 "Bad address" UserInfo={ABFileDescriptor=-1}
The operation couldn’t be completed. (Foundation._GenericObjCError error 0.)

关于可能导致此问题的任何想法?

编辑:另请注意,这是为 macOS 10.14 SDK 编译的,并在 macOS 10.14.3 上运行

最佳答案

答案是在Capabilities的App Sandbox部分勾选App Data的Contacts复选框,然后打开App Sandbox的开关。

关于swift - CNContactStore 执行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54818121/

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