gpt4 book ai didi

ios - 如何更新CNContact?获取 CNErrorDomain 代码=2

转载 作者:行者123 更新时间:2023-11-28 10:15:36 27 4
gpt4 key购买 nike

我正在尝试更新您在种姓 Controller 中的联系人,所有这些都保存完好,这是在添加具有 CNLabeledValue <CNPhoneNumber> 的新号码时格式。我带来了控制台结果我收到了这个错误

CNErrorDomain Code = 2 "(null)" UserInfo = {CNKeyPaths = (
     phoneNumbers
)},

当我查看如何创建酒店的本质时,他们没有指标的示例
<CNLabeledValue: 0x1706755c0: identifier = (null), label = iPhone, value = <CNPhoneNumber: 0x170439100: countryCode = ru, digits = + ***** >>

我的代码
  for i in 0..<contactPhoneEditTableViewRowIndex {
debugPrint("i", i)
if let editRow = getEditPhoneRow(i) {
if !editRow.isHidden {
let phone = editRow.cell.phoneNumberTextField.text ?? ""
let label = editRow.cell.titlePhoneButton.titleLabel?.text ?? ""
if phone != "" {
let phoneModel = CNLabeledValue<CNPhoneNumber>().settingLabel(label, value: CNPhoneNumber(stringValue: phone))

phones.append(phoneModel)
}
}
}
}

debugPrint(phones)

guard let updatedContactModel = contactModel.contact.mutableCopy() as? CNMutableContact else { return }

updatedContactModel.givenName = first
updatedContactModel.familyName = last
updatedContactModel.organizationName = company
updatedContactModel.phoneNumbers = phones

contactManager.updateContact(updatedContactModel) { [weak self] (error) in
if error == nil {
self?.dismiss(animated: true, completion: nil)
} else {
DispatchQueue.main.async {
SVProgressHUD.showError(withStatus: error!.localizedDescription)
}
}
}

ContactManager 中的这个功能
func updateContact(_ contact: CNMutableContact, completion: ((_ error: Error?) -> Void)?) {
let req = CNSaveRequest()
req.update(contact)
let store = CNContactStore()
do {
try store.execute(req)
debugPrint("updateContact success")
completion?(nil)
} catch {
completion?(error)
let _error = error as NSError
debugPrint(_error)
}
}

告诉我如何解决这个问题?

最佳答案

我改变了这段代码

let phoneModel = CNLabeledValue<CNPhoneNumber>().settingLabel(label, value: CNPhoneNumber(stringValue: phone))

let phoneModel = CNLabeledValue(label: phoneLabel, value: CNPhoneNumber(stringValue: phone))它解决了我的问题

关于ios - 如何更新CNContact?获取 CNErrorDomain 代码=2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42042370/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com