我的应用程序中有一个奇怪的错误,我找不到任何解决办法/修复方法。出于某种原因,我可以将地址保存到与社交网站(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)
}发布于 2017-04-05 02:37:36
好的,所以我得到了苹果的回应,这个行为是有意的。开发人员应该检测到这个策略违规,然后提供创建一个新的联系人,然后链接这两个联系人。
发布于 2018-12-12 10:30:06
我理解苹果为什么这么做,因为社交账户没有存储与(比方说) iCloud联系人相同的数据,所以你需要把这些值保存在其他地方(而且你不能把联系人转换成iCloud,因为社交账户会丢失它的数据)。
我不认为你可以选择以编程方式链接联系人,对吗?
据我所知,iOS将决定两个联系人是否相同--可能在多个值匹配(?)您可以检测到两个给定的联系人是否连接在一起。
https://stackoverflow.com/questions/40568549
复制相似问题