简体   繁体   中英

IOS9 Contacts framework fails to update linked contact

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM