A property was not requested when contact was fetched


I’m trying to get contact.nickname when using cnContactPickerMBS. The contact is returned OK but when I try to access the nickname property I get the above NSExceptionMBS. Is there something I should be adding to the picker request?

It would be MUCH better if you actually showed the code you are using. I’m always puzzled that people running into problems think others have telepathic powers. Do you actually hold on to the returned contact somewhere before trying to use it? As I said: show what you are doing and you might get help a LOT faster.

This in the didSelectContact event of cnContactPickerMBS

Sub DidSelectContact(contact as CNContactMBS)

dim nn as string = contact.nickname
End Sub

And this to call it:

Dim b As NSButtonMBS = Me.NSButtonMBS

picker = new MyCNContactPickerMBS

dim r as new NSRectMBS(0,0,200,300)

picker.showRelativeToRect(r, b, picker.MaxXEdge)

…and PS I have no idea how to get this code quoting function to work properly on this forum.

This is the whole code?

You are aware that nn ceases to exist when you leave the event? And that you do not store the retrieved contact anywhere, so it also goes out of scope and disappears?

Please read up on scope.

Markus. Yes, pretty much the whole code for this example. nn is in-scope when it is defined and that is where the nsExceptionMBS is raised.

Does your app have the entitlement to access the contacts then? Usually you are asked if you allow an app to access your contacts. Might even need to be signed.

Yes, that is not the problem. The event returns the contact correctly and I am able to access other properties like givenName, familyName etc - but for some reason nickName seems to be a no-no.

So you can see the nickname in the debugger?

I can see the property, but its contents are empty.

A note in the MBS documentation says “The contact may only be partial loaded and not have all fields available as the picker may not need/show all fields.”

Yes, I saw that, hence my original question viz: is there something I need to add to the picker request to get other fields?

Previously AddressBook allowed access to the other fields, but cnContacts seems to be more limited, so it messes up the app somewhat.

It may be that I have to ditch the cnContactPicker and build my own picker using cnContactStoreMBS instead. That would appear to give more control over the fields provided.

I run a modified MBS example and get as reason for the exception “A property was not requested when contact was fetched.”

You can’t even test for the nickname being empty as

If contact.nickname <> "" Then
  log " Nickname: " + contact.nickname
End If

also results in the exception on the first line.

Yes, have to use contact.isKeyAvailable(key) to test for the property’s availability first. Seems a bit long-winded.

This works:

Sub DidSelectContact(contact as CNContactMBS) Handles DidSelectContact
  log CurrentMethodName
  log "Contact: "+contact.givenName + contact.familyName
  Dim e As NSErrorMBS
  Dim c As CNContactMBS = app.ContactStore.unifiedContactWithIdentifier(contact.identifier, e)
  Log "Contact: "+c.givenName + c.familyName + c.nickname

  // keep for later?
  self.Current = contact
End Sub

Thank you Marcus - yes that is what I was looking for.

1 Like

With a k please :wink:

And btw you do get the code coloring by using three backticks on their own line before and after the code:

these ones: ```

Tks again Markus :slight_smile:

I was trying to use the </> button but the three ticks seems to work better.

Same here. Don’t forget to mark it as answered.

Yes, I am sorry for partial fetched contacts.
We try to avoid them, but when the contact comes from the panel, it may not load a fields.

Hi Christian,

you might want to add my added lines to your example to show how to get the missing information for a partial contact.