Hey, I would love to access the users Contact (ie. the Me Card) Apple recently released the Invites app and within this app you can find the users Contacts Photo. I tried to replicate this behaviour but I currently need to match based on a name or email or something else. I have no idea how to receive this data because when using the Invites app I only remember the app asking for Contacts permission and nothing else so far.
let store = CNContactStore()
let keysToFetch = [CNContactImageDataAvailableKey, CNContactImageDataKey, CNContactThumbnailImageDataKey] as [CNKeyDescriptor]
let email = "test@test.de"
let predicate = CNContact.predicateForContacts(matchingEmailAddress: email)
do {
let contacts = try store.unifiedContacts(matching: predicate, keysToFetch: keysToFetch)
let imageDatas: [Data] = contacts.compactMap { $0.imageData }
self.images = imageDatas.map { UIImage(data: $0) ?? UIImage() }
} catch {
print("Error fetching contacts: \(error)")
}
This is how I am retrieving the Image. MAYBE someone can help me out.
Thank you so far
~ Flo