더 현대적인 CNContactPickerViewController
을 사용하여 연락처를 선택하려고합니다. 연락처에 주소가 여러 개인 경우 사용자가 주소 중 하나만 선택할 수있게하려고합니다. 주소가 구체적으로 선택되면 CNContact
개체도 가져 오려고합니다.CNContactPickerViewController를 사용하여 주소 및 연락처를 가져 오는 방법은 무엇입니까?
나는이 위임 기능을 사용할 수 있었다되지 않는 ABPeoplePickerNavigationControllerDelegate
사용하여이 작업을 수행 할 수 있습니다 : CNContactPickerViewController
를 사용하는 경우,
func peoplePickerNavigationController(_ peoplePicker: ABPeoplePickerNavigationController, didSelectPerson person: ABRecord, property: ABPropertyID, identifier: ABMultiValueIdentifier)
그러나,이 관련 위임 기능을 사용할 수 있습니다 :
func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty)
참고 CNContact
오브젝트가 리턴되지 않습니다. contactProperty에 CNPostalAddress
이 있지만 소유 한 연락처의 레코드를받지 못했습니다.
여기에 내가 ABPeoplePickerNavigationController
으로 사용되는 코드입니다 :
let peoplePicker = ABPeoplePickerNavigationController()
peoplePicker.peoplePickerDelegate = self
peoplePicker.displayedProperties = [NSNumber(value: kABPersonAddressProperty as Int32), NSNumber(value: kABPersonBirthdayProperty as Int32)]
peoplePicker.predicateForSelectionOfPerson = NSPredicate(format: "[email protected]unt <= 1")
peoplePicker.modalPresentationStyle = UIModalPresentationStyle.currentContext
self.present(peoplePicker, animated: true, completion: nil)
는 ... 여기 CNContactPickerViewController와 코드입니다 :
let contactPicker = CNContactPickerViewController()
contactPicker.delegate = self
contactPicker.displayedPropertyKeys = [CNContactPostalAddressesKey, CNContactBirthdayKey]
contactPicker.predicateForSelectionOfContact = NSPredicate(format: "[email protected] <= 1")
contactPicker.modalPresentationStyle = UIModalPresentationStyle.currentContext
self.present(contactPicker, animated: true, completion: nil)
그래서, 나에게, 그것은 동일한 기능처럼 보이는이 더 이상 새 연락처 프레임 워크에서 사용할 수 있지만 여기에서 뭔가를 놓친 지 확인하고 있습니다.
내 실수로 '연락처'속성에 대한 CNPostalAddress가 표시됩니다. contactProperty를 보는 대신. – Daniel