将联系人地址保存到统一联系人会导致(CNErrorDomain错误500) [英] Saving Contact Address to Unified Contact results in (CNErrorDomain error 500)
问题描述
我的应用程序中出现一个奇怪的错误,我找不到任何解决方法/修复方法.由于某种原因,我能够将地址保存到未与社交资料(Facebook,Twitter等)统一的联系人.但是,当我尝试为与Facebook或Twitter统一的联系人添加地址时,出现奇怪的保存错误:
There is an odd error in my application that I can't find any workarounds/fixes for. For some reason, I'm able to save an address to a contact that isn't unified with a social profile (Facebook, Twitter, etc). However, when I try to add an address for my contact that is unified with Facebook or Twitter I get a weird save error:
The operation couldn’t be completed. (CNErrorDomain error 500.)
以下是我正在使用的一些代码:
Here is some of the code that I'm using:
if mutableContact.isKeyAvailable(CNContactPostalAddressesKey) {
var postalAddresses = [CNLabeledValue<CNPostalAddress>]()
for address in self.contactAddresses {
let postalAddress: CNLabeledValue<CNPostalAddress> = CNLabeledValue(label: CNLabelOther, value: address)
postalAddresses.append(postalAddress)
}
mutableContact.postalAddresses = postalAddresses
}
let saveRequest = CNSaveRequest()
if isNewContact {
saveRequest.add(mutableContact, toContainerWithIdentifier: nil)
} else {
saveRequest.update(mutableContact)
}
do {
try contactStore.execute(saveRequest)
} catch let error as NSError {
print(error.localizedDescription)
let alertController = UIAlertController(title: "Failed to save/update contact!", message: "Unfortunatly, the app couldn't add or make modifications to your contact. Please try again or use the Contacts app to preform changes.", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "Okay", style: .cancel) {
action in
self.dismiss(animated: true, completion: nil)
}
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
}
推荐答案
好,所以我得到了Apple的回应,这是有意的.开发人员应检测到这种违反政策的行为,然后提出要创建一个新联系人,然后链接这两个联系人.
Ok, so I have gotten a response from Apple and this behavior is intended. Developers should detect this policy violation and then offer to create a new contact and then link the two contacts.
这篇关于将联系人地址保存到统一联系人会导致(CNErrorDomain错误500)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!