CNContact添加了新的联系人问题



我在通过联系人框架添加联系人时遇到了问题。

我使用设备iPhone 5s与iOS 12.1.2

我添加联系人的代码如下::

let saveRequest = CNSaveRequest()
saveRequest.add(self, toContainerWithIdentifier: nil)
do {
    try contactStore.execute(saveRequest)
} catch let error {
    print("Error occurred while saving the request (error)")
}
每次错误如下

::

保存请求时出错 域错误 = CNError域代码 =1 "通信错误" 用户信息={NSLocalizedDescription=通信错误,NSLocalizedFailureReason=尝试与联系人服务通信时出错。}

现在对这个错误有任何影响吗?

我找不到任何关于这个的东西。

要为CNcibtactStore添加单例,只需添加

/**
 A var to store CNContactStore
 */
let mContactStore = CNContactStore.init()

AppDelegate.swift文件中。

要在任何地方使用它,只需使用此代码

 contactStore = appDelegate.mContactStore

这将为我解决问题,希望也能为您解决问题。

最新更新