developer website.
We going to see how to use the Contacts framework.
To pick a contact, you create CNContactPickerViewController
, and then provide a delegate to handle events. The CNContactPickerViewController
comes from the ContactsUI
.
1 2 3 4 5 6 | var contactPicker = new CNContactPickerViewController(); // Make the current class the delegate contactPicker.Delegate = this; // Present the controller PresentViewController(contactPicker, true, null); |
Since we made the delegate the current class, we will need to implement an interface, ICNContactPickerDelegate
as follows:
1 2 3 | public partial class ViewController : UIViewController, ICNContactPickerDelegate { } |
To get the contact, we implement the method DidSelectContact()
as follows:
1 2 3 4 5 | [Export("contactPicker:didSelectContact:")] public void DidSelectContact(CNContactPickerViewController picker, Contacts.CNContact contact) { Debug.WriteLine($"Selected contact {contact.GivenName} {contact.PhoneNumbers[0].Value.StringValue}"); } |