5

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")
        }
    }
Shalabh
  • 687
  • 1
  • 6
  • 11
  • Currently I am facing the issue with almost same scenario in ios 12.1.2 iPhone 5s device and also with all simulators. – The iOSDev Jan 23 '19 at 11:40
  • I have added almost same question [here](https://stackoverflow.com/questions/54326775/cncontact-add-new-contact-issue). Please post here or in the question given above if there is any progress on this issue – The iOSDev Jan 23 '19 at 12:14
  • anyone found the solution?? I found same issue – A.s.ALI Jan 30 '20 at 05:27
  • Please check [this answer](https://stackoverflow.com/a/60039035/1132951), this may solve your issue – The iOSDev Feb 04 '20 at 05:54

0 Answers0