IOS9 Contacts framework fails to update linked contact
Asked Answered
D

1

6

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!

Durarte answered 24/2, 2016 at 12:34 Comment(2)
I have the same problem. contactStore.executeSaveRequest(saveRequest) is throwing an error. Someone help us!Babb
Nothing seems to indicate that you can't modify a linked contact. Did you check the authorisation status of your contact store before trying to do the save request?Cuesta
M
0

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

Maxine answered 15/7, 2019 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.