IOS9 Contacts framework fails to update linked contact

590 views Asked by At

In AddressBook on device I have a record linked with Facebook contact record. I fetch it into CNContact with CNContactFetchRequest with:

contactFetchRequest.mutableObjects = true  
contactFetchRequest.unifyResults = false  

After getting, I modify it, then I trying to update it with:

let store = CNContactStore()  
let saveRequest = CNSaveRequest()  
if contact != nil {  
    mutableContact = contact!.mutableCopy() as! CNMutableContact  
    saveRequest.updateContact( mutableContact )  
} else {  
    mutableContact = CNMutableContact()  
    saveRequest.addContact( mutableContact, toContainerWithIdentifier:nil )  
}  
// Modify mutableContact  
mutableContact.jobTitle = "Worker";  

do {  
    // Will fails with error  
    try store.executeSaveRequest(saveRequest)  
} catch let error as NSError {  
    BCRLog(error)  
    self.isFailed = true  
} catch {  
    self.isFailed = true  
}

On execute executeSaveRequest, I caught an error:

NSError with domain:CNErrorDomain, code:500 (witch is CNErrorCodePolicyViolation), _userInfo: {"NSUnderlyingError" : {"ABAddressBookErrorDomain" - code 0}} witch is kABOperationNotPermittedByStoreError

The question: Is it possible to modify linked contact (not unified), and if it is, what i do wrong?

If I modifying not linked contact - all OK!

1

There are 1 answers

0
adnako On

I have this error when the Contacts app is configured to store contacts in an Exchange account. When I choose an iCloud account as a default it immediately saves a contact well. I can check what is set on your device in Settings -> Contacts -> Default Account