Obtaining a share participant's avatar image

Are the user icons/avatars seen in UICloudSharingController available through an API? I don't see them in CKUserIdentity or CKUserIdentity.LookupInfo...

Replies

I've determined that the icons/avatars are indeed available, but through ContactsKit rather than CloudKit. The images shown are all images you have personally associated with the user's Contact entry in your Contacts app.

How to retrieve the images: let share = mySharedRecord.share let participants = share.participants let userIdentities = participants.map {$0.userIdentity} let emails = userIdentities.compactMap {$0.lookupInfo?.emailAddress}

let store = CNContactStore() let keysToFetch = [CNContactImageDataAvailableKey, CNContactImageDataKey, CNContactThumbnailImageDataKey] as [CNKeyDescriptor]

emails.forEach { email in do { let predicate = CNContact.predicateForContacts(matchingEmailAddress: email) let contacts = try store.unifiedContacts(matching: predicate, keysToFetch: keysToFetch) let imageDatas: [Data] = contacts.compactMap {$0.imageData} let images = imageDatas.map {UIImage(data: $0)} return images } catch { // Handle the error return nil } }