我的应用程序中存在一个奇怪的错误,我找不到任何解决方法/修复程序。出于某种原因,我能够将地址保存到未与社交资料(Facebook、Twitter 等)统一的联系人。但是,当我尝试为我的联系人添加与 Facebook 或 Twitter 统一的地址时,我收到一个奇怪的保存错误:
The operation couldn’t be completed. (CNErrorDomain error 500.)
这是我正在使用的一些代码:
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 的回复,这种行为是有意为之的。开发人员应检测到这种违反政策的行为,然后提出创建新联系人并将这两个联系人关联起来。
关于ios - 将联系人地址保存到统一联系人会导致(CNErrorDomain 错误 500),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40568549/