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

how to update CNContact? Get CNErrorDomain Code=2

我正在尝试更新您在种姓控制器中的联系人,在一定程度上都保存完好,这是在添加具有 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)),它解决了我的问题