0
카스트 컨트롤러에서 연락처를 업데이트하려고합니다. 모든 내용이 잘 보존되어 있습니다. CNLabeledValue <CNPhoneNumber>
형식의 새 번호를 추가 할 때입니다. 나는이 호텔의 본질을 생성하는 방법을 보면서 나는이 오류CNContact를 업데이트하는 방법은 무엇입니까? CNErrorDomain Code = 2
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)
}
}
}
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)
}
}
ContactManager
에서이 기능
해결 방법 알려주십시오.