首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CNContactStore执行失败

CNContactStore执行失败
EN

Stack Overflow用户
提问于 2019-02-22 00:07:04
回答 2查看 346关注 0票数 1

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

代码语言:javascript
复制
    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")
        }
    })

..and --这是结果:

代码语言:javascript
复制
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.14SDK编译的,并且运行在macOS 10.14.3上。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-22 08:32:36

答案是选中and部分中and部分中的App的联系人复选框,然后打开and的开关。

票数 0
EN

Stack Overflow用户

发布于 2019-02-22 06:49:57

确保您在Info.plist中添加了键Info.plist。

请参考链接

重要 在iOS 10.0上或之后链接的iOS应用程序必须在其Info.plist文件中包含需要访问的数据类型的使用说明键,否则会崩溃。要具体访问联系人数据,必须包括NSContactsUsageDescription。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54818121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档