我正在尝试将手机中的联系人从Exchange容器移动到iCloud容器-但是我遇到了一个奇怪的错误,无法找到任何解决方案..你们中有人遇到过此问题吗?
2018-10-01 20:18:27.501591 + 0300 ContactManager [9630:1988935] [联系人]与XPC服务通信时出错:错误 域= NSCocoaErrorDomain代码= 4097“连接到名为服务 com.apple.contactsd“ UserInfo = {NSDebugDescription =连接到 名为com.apple.contactsd的服务} 2018-10-01 20:18:27.502257 + 0300 ContactManager [9630:1988988] [联系人]错误:到com.apple.contactsd的服务连接为 打断 保存联系人错误时出错域= CNErrorDomain代码= 1“通信错误” UserInfo = {NSLocalizedDescription =通信 错误,NSLocalizedFailureReason =尝试执行时发生错误 与通讯录服务通信。}
下面的代码段
func moveContactFromContainer(sourceContainer: CNContainer, destinationContainer: CNContainer){
let predicate = CNContact.predicateForContactsInContainer(withIdentifier: sourceContainer.identifier)
do{
let results = try contactStore.unifiedContacts(matching: predicate, keysToFetch: keysToFetch as! [CNKeyDescriptor])
for result in results{
print(result.givenName)
//print(result.phoneNumbers)
let mutableContact1 = result.mutableCopy() as! CNMutableContact
let saveRequest1 = CNSaveRequest()
saveRequest1.delete(mutableContact1)
do {
try contactStore.execute(saveRequest1)
} catch {
print("Error while deleting Contact \(error)")
}
let mutableContact = result.mutableCopy() as! CNMutableContact
let saveRequest = CNSaveRequest()
saveRequest.add(mutableContact, toContainerWithIdentifier: destinationContainer.identifier)
do {
try contactStore.execute(saveRequest)
} catch {
print("Error while saving Contact \(error)")
exit(0)
}
}
print(results.count)
}catch{
print("Error")
}
}