3

我在通过Contact Framework添加联系人时遇到问题。

我使用 iOS 12.1.2 设备 iPhone 5s

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

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

每次都会出现如下错误::

保存请求时出错 Error Domain=CNErrorDomain Code=1 "Communication Error" UserInfo={NSLocalizedDescription=Communication Error, NSLocalizedFailureReason=尝试与联系人服务通信时出错。}

现在给任何人关于这个错误的任何信息吗?

我无法找到任何关于此的事情。

4

1 回答 1

1

CNcibtactStore刚刚添加的单例添加

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

AppDelegate.swift档。

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

 contactStore = appDelegate.mContactStore

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

于 2020-02-03T12:14:11.700 回答