Display contact address in ios using xamarin

82 Views Asked by At

absolute beginner with xamarin. Followed the following tutorial to try and simply click a button to display the contact list, select a contact, and then to display firstname, surname, and address on the screen. https://github.com/xamarin/recipes/tree/master/Recipes/ios/shared_resources/contacts/choose_a_contact

Managed to get the firstname and surname to be displayed, but cannot get the address. Constantly getting the error

Foundation.MonoTouchException: Objective-C exception thrown.  Name: CNPropertyNotFetchedException Reason: A property was not requested when contact was fetched.    

On the

contanct.PostalAddresses

This is the snippet of code:-

partial void UIButton197_TouchUpInside(UIButton sender)
    {

        // Create a new picker
        var picker = new CNContactPickerViewController();

        // Select property to pick
        picker.DisplayedPropertyKeys = new NSString[] { CNContactKey.GivenName, CNContactKey.FamilyName, CNContactKey.PostalAddresses };

        // Respond to selection
        var pickerDelegate = new ContactPickerDelegate();
        picker.Delegate = pickerDelegate;

        pickerDelegate.SelectionCanceled += () => {
             SelectedContact1.Text = "";
        };

        pickerDelegate.ContactSelected += (contact) => {
            SelectedContact1.Text = contact.GivenName;
            SelectedContact2.Text = contact.FamilyName;
            SelectedContact3.Text = contact.PostalAddresses
        };

        pickerDelegate.ContactPropertySelected += (property) => {
            SelectedContact1.Text = property.Value.ToString();
        };

        // Display picker
        PresentViewController(picker, true, null);
    }

Am i missing something?

1

There are 1 best solutions below

0
On

Seem to have resolved this if anyone else is having a similar issue.

The solution was to completely close down visual studio on the mac and re-open it. Originally, i was stopping the project, and re-building. Possibly a bug, but non of my changes where being picked up.

A simple re-start kicked it back in