Created
July 24, 2014 03:16
-
-
Save timefrancesco/829a49476bd10e597049 to your computer and use it in GitHub Desktop.
Revisions
-
timefrancesco renamed this gist
Jul 24, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
timefrancesco created this gist
Jul 24, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ /* A simple snippet to Open the Address book in iOS and select a person's email address and add it to the textfield (_addressesTextView) PLATFORM: XAMARIN iOS */ ABPeoplePickerNavigationController _contacts; partial void AddEmail (NSObject sender) { if (_contacts == null) _contacts = new ABPeoplePickerNavigationController (); _contacts.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; PickerDelegate pickerDeleg = new PickerDelegate(); pickerDeleg.emailSelected += (email) => { if (_addressesTextView.Text.Length > 0) _addressesTextView.Text = _addressesTextView.Text + "," + email; else _addressesTextView.Text = email; }; _contacts.Delegate = pickerDeleg; this.PresentViewController(_contacts,true,null); } //People Picker Delegate public class PickerDelegate:ABPeoplePickerNavigationControllerDelegate { public delegate void EmailSelectedDelegate(string email); public event EmailSelectedDelegate emailSelected; public override bool ShouldContinue (ABPeoplePickerNavigationController peoplePicker, IntPtr selectedPerson, int propertyId, int identifier) { if (propertyId == 4) { //kABPersonEmailProperty //this is a bug in XAMARIN, check this: https://bugzilla.xamarin.com/show_bug.cgi?id=16072 ABPerson person = Runtime.GetINativeObject<ABPerson> (selectedPerson,false); var emails = person.GetEmails(); int index = emails.GetIndexForIdentifier(identifier); var values = emails.GetValues(); emailSelected(values[index]); peoplePicker.DismissViewController(true,null); } return false; } public override void Cancelled (ABPeoplePickerNavigationController peoplePicker) { peoplePicker.DismissViewController(true,null); } }