contact picture

Is it possible to get the current user’s contact picture, or contact pictures from the address book?
This is not an essential part of my app, but I think it could be very cool.

Yes, CNContact class has imageDate and thumbnailImageData properties.

How are you getting the contacts ?
Listing all contacts of the device or displaying a Contact Picker to retrieve one contact at a time?

Jeremie, that was going to be my next challenge. I was hoping to try to auto-identify based on name or email address. Any tips there?

If I understand, the user of the app types a name or email address and the app will retrieve contact information automatically based on that?

In that case you do not want a contact picker like I use in Secret Santa: https://scrtsanta.app
but you will need to use CNContactStore https://developer.apple.com/documentation/contacts/cncontactstore to retrieve all contacts.

This looks above my head. I have never done any declares for iOS (yet)

Cute secret Santa app!

For me the use is a little different.
My app can have connected users. If the user name is their email or logically close to one in the contact, I’d like to use that.
I can also push them to setup an icon how we do it in this form too, but I was hoping for less work on the end-users side.

If you only need access to ContactStore for a profile picture, it is too much work for so little benefit.

I would recommend doing it the same way as on the forum, using Gravatar.
And I also use that in Secret Santa.

[code]Dim hash As Text = EncodeHex(xojo.Crypto.MD5(xojo.core.TextEncoding.UTF8.ConvertTextToData(email))).Lowercase

// d = 404 (no image)
// d = mp (mystery person)
// s = size of thumbnail

Dim url As Text = “https://www.gravatar.com/avatar/” + hash + “?d=mp&s=120”

//Fetch URL using Xojo.net.httpsocket
[/code]

[code]Private Function EncodeHex(data As Xojo.Core.MemoryBlock) as Text

Dim v() As Text
Dim n As UInteger=data.Size-1
For i As UInteger=0 To n
v.Append data.UInt8Value(i).ToHex(2)
Next
Return Text.Join(v,"")
End Function
[/code]

awesome. Thanks.

What if you only wanted the user’s own photo and not access the full contact library?

Can’t have the users photo without full access I believe. Any reason you can’t have them take/select a photo to use?

I can do that for sure. I just wanted it to be there without any additional effort from the user.

I think you would find that most people don’t have their contact pictures filled in anyway. Of the 20 or so people I know well with iPhones maybe 2 have any pictures saved in their contacts. Prompting the user to take a picture for their profile if they so choose is most likely the best option I think.

you are probably right.