2017-02-04 3 views
0

カーストコントローラの連絡先を更新しようとしていますが、ポイントまで保存されています。これはCNLabeledValue <CNPhoneNumber>という形式の新しい番号を追加するときです。私はホテルの本質を作成する方法を見て、彼らはインジケータCNContactを更新するには? Get CNErrorDomain Code = 2

<CNLabeledValue: 0x1706755c0: identifier = (null), label = iPhone, value = <CNPhoneNumber: 0x170439100: countryCode = ru, digits = + ***** >> 

私のコード

の例を持っていないとして、私は私が

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

このエラーを取得し、コンソールの結果をもたらしました

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) 
    } 
} 
から

この問題を解決する方法を教えてください。

答えて

2

私はlet phoneModel = CNLabeledValue(label: phoneLabel, value: CNPhoneNumber(stringValue: phone))にこのコード

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

を変更し、それは私の問題を解決し

関連する問題