2016-09-22 4 views
1

더 현대적인 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) 

그래서, 나에게, 그것은 동일한 기능처럼 보이는이 더 이상 새 연락처 프레임 워크에서 사용할 수 있지만 여기에서 뭔가를 놓친 지 확인하고 있습니다.

+0

내 실수로 '연락처'속성에 대한 CNPostalAddress가 표시됩니다. contactProperty를 보는 대신. – Daniel

답변

3

CNContact 개체가 반환되지 않습니다. contactProperty에 CNPostalAddress이 있지만 소유자 연락처의 레코드를받지 못했습니다.

그러나

CNContact 목적은 CNContactPropertycontact 속성에서 검색 할 수

그래서 ... CNContactPickerViewController를 사용 만이 관련 대리자 기능 가능 :

func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty) 

...이 위임 메서드를 구현하면 어떤 작업을 수행 할 수 있습니까? 너를 원해. 하지만 당신이 있는지 확인하려면 당신 같은 다른 대리자 메서드 구현 하지 위치 : 피커에게 접촉 (그리고 그 속성)를 선택하는 순간을 기각한다

func contactPicker(CNContactPickerViewController, didSelect: CNContact) 

합니다.

더 CNContact이 없음을
1

주 당신은 그것에 대해 단지 틀렸다

객체. 대리자 메서드는 contactPicker(_:didSelect:)이고, CNContactProperty를 전달하고 CNContactProperty는 전체 CNContact 및 모든 속성을 전달합니다.