連絡先を選択するのに、より現代的なCNContactPickerViewController
を使用しようとしています。連絡先に複数のアドレスがある場合は、ユーザーが1つのアドレスだけを選択できるようにします。アドレスが具体的に選択されている場合は、CNContact
オブジェクトも取得する必要があります。CNContactPickerViewControllerを使用して住所と連絡先を取得する方法
私はこのデリゲート機能が利用可能であった非推奨ABPeoplePickerNavigationControllerDelegate
、使用してこれを行うことができます:CNContactPickerViewController
を使用した場合、
func peoplePickerNavigationController(_ peoplePicker: ABPeoplePickerNavigationController, didSelectPerson person: ABRecord, property: ABPropertyID, identifier: ABMultiValueIdentifier)
しかし、これだけ関連するデリゲートの機能が提供されています:
func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty)
。なお、 CNContact
オブジェクトが返されません。私はCNPostalAddress
をcontactPropertyに持っていますが、私は所有している連絡先のレコードを受け取っていません。
ここで私が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] <= 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