I am trying to move contacts in my Phone from Exchange Container to iCloud Container - but i am facing a strange error, unable to find any solutions yet .. has anyone of you faced this problem?
2018-10-01 20:18:27.501591+0300 ContactManager[9630:1988935] [Contacts] Error communicating with XPC Service: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.contactsd" UserInfo={NSDebugDescription=connection to service named com.apple.contactsd} 2018-10-01 20:18:27.502257+0300 ContactManager[9630:1988988] [Contacts] Error: service connection to com.apple.contactsd was interrupted Error while saving Contact Error Domain=CNErrorDomain Code=1 "Communication Error" UserInfo={NSLocalizedDescription=Communication Error, NSLocalizedFailureReason=An error occurred while trying to communicate with the Contacts service.}
Snippet of Code below:
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")
}
}