« Comment Links in File… | Home | Multi Year Updates »

CNContactPickerViewController for Xojo

You may know that our MBS Xojo Plugins contain classes for Contacts for macOS and iOS. And now we add a new CNContactPickerViewControllerMBS class, so you can use the standard picker on iOS to pick a contact.

You subclass the CNContactPickerViewControllerMBS class and fill the events or use addHandler to connect the events to your methods. There is didCancel event in case user presses cancel button and there are events for one (or multiple) contacts selected or contact properties. Depending on which event you implement, the picker will be single or multi selection and may show contact properties.

So let's subclass and fill the events:

Class MyCNContactPickerViewControllerMBS Inherits CNContactPickerViewControllerMBS
Sub didCancel() System.DebugLog CurrentMethodName End EventHandler
Sub didSelectContact(contact as CNContactMBS) MessageBox "Picked: " + contact.givenName + " " + contact.familyName End EventHandler
End Class

Next we want to use it. So in your screen, view or button subclass, you can just make a new picker object and keep it somewhere. Since all processing asynchron, please keep a reference stored some. To show we simply call Present method:

Class MyScreen
Sub ButtonPressed() picker = New MyCNContactPickerViewControllerMBS picker.Present End Sub
Property picker As myCNContactPickerViewControllerMBS
End Class

Once you pick a contact or cancel, the dialog closes automatically an you can continue to work with the CNContactMBS or CNContactPropertyMBS object. Please try with 22.3pr2 or newer.

08 06 22 - 09:49