ContactPicker

internal actual class ContactPicker(source)

Android-specific implementation of the ContactPicker contract.

This implementation utilizes the Android ContactsContract provider and the Activity Result API (ActivityResultContracts.PickContact) to enable secure and seamless contact selection.

It manages the lifecycle of the activity launcher and performs background queries to the ContentResolver to aggregate contact details like names, multiple phone numbers, emails, and avatars.

internal expect class ContactPicker(source)

An expected class that defines the contract for a platform-specific contact picker.

This class facilitates the selection of contacts from the device's native address book. Implementations are provided for different platforms (e.g., Android and iOS) to handle the specific APIs and UI flows required by each.

internal actual class ContactPicker : NSObject, CNContactPickerDelegateProtocol(source)

iOS-specific implementation of the ContactPicker contract.

This implementation leverages the native CNContactPickerViewController from the ContactsUI framework to provide a familiar and secure contact selection experience for iOS users.

It acts as both the launcher and the delegate (CNContactPickerDelegateProtocol) to handle lifecycle events and data extraction from the native CNContact objects.

Constructors

Link copied to clipboard
constructor()
expect constructor()
constructor()

Properties

Link copied to clipboard
private val contactPicker: CNContactPickerViewController
Link copied to clipboard
Link copied to clipboard
expect val description: String?
Link copied to clipboard
expect val hash: NSUInteger
Link copied to clipboard
private lateinit var onContactSelected: (Contact?) -> Unit
Link copied to clipboard
private lateinit var picker: ManagedActivityResultLauncher<Void?, Uri?>
Link copied to clipboard
private val projection: Array<String>

Columns queried from the ContactsContract.Contacts table.

Link copied to clipboard
expect val superclass: ObjCClass?

Functions

Link copied to clipboard
expect open override fun class(): ObjCClass?
Link copied to clipboard
expect open override fun conformsToProtocol(aProtocol: objcnames/classes/Protocol??): Boolean
Link copied to clipboard
open override fun contactPicker(picker: CNContactPickerViewController, didSelectContact: CNContact)

Invoked by the system when the user selects a specific contact.

expect open fun contactPicker(picker: CNContactPickerViewController, didSelectContactProperties: List<*>)
expect open fun contactPicker(picker: CNContactPickerViewController, didSelectContacts: List<*>)
expect open fun contactPicker(picker: CNContactPickerViewController, didSelectContactProperty: CNContactProperty)
Link copied to clipboard
open override fun contactPickerDidCancel(picker: CNContactPickerViewController)

Invoked by the system when the user cancels the contact picker.

Link copied to clipboard
expect open fun copy(): Any?
Link copied to clipboard
expect open fun debugDescription(): String?
Link copied to clipboard
expect open override fun description(): String?
Link copied to clipboard
expect open fun doesNotRecognizeSelector(aSelector: COpaquePointer?)
Link copied to clipboard
expect open fun finalize()
Link copied to clipboard
private fun findTopMostViewController(rootViewController: UIViewController?): UIViewController?

Recursively traverses the view controller hierarchy to find the visible controller.

Link copied to clipboard
expect open fun forwardingTargetForSelector(aSelector: COpaquePointer?): Any?
Link copied to clipboard
expect open fun forwardInvocation(anInvocation: objcnames/classes/NSInvocation??)
Link copied to clipboard
private fun getContactAvatar(context: Context, contactId: Long): ByteArray?

Resolves the contact's photo into a ByteArray.

Link copied to clipboard
private fun getContactFromUri(context: Context, uri: Uri): Contact?

Extracts comprehensive contact data from the provided Uri.

Link copied to clipboard
private fun getEmail(context: Context, contactId: String): List<String>

Queries the ContactsContract.CommonDataKinds.Email table for all addresses associated with a contact.

Link copied to clipboard
private fun getEmailAddress(emailAddresses: List<*>): List<String>

Utility to extract string representations of email addresses from CNLabeledValues.

Link copied to clipboard
private fun getPhoneNumber(context: Context, contactId: String): List<String>

Queries the ContactsContract.CommonDataKinds.Phone table for all numbers associated with a contact.

Link copied to clipboard
private fun getPhoneNumbers(contactList: List<*>): List<String>

Utility to extract string representations of phone numbers from CNLabeledValues.

Link copied to clipboard
expect open override fun hash(): NSUInteger
Link copied to clipboard
expect open fun init(): NSObject?
Link copied to clipboard
expect open override fun isEqual(object: Any?): Boolean
Link copied to clipboard
expect open override fun isKindOfClass(aClass: ObjCClass?): Boolean
Link copied to clipboard
expect open override fun isMemberOfClass(aClass: ObjCClass?): Boolean
Link copied to clipboard
expect open override fun isProxy(): Boolean
Link copied to clipboard
actual fun launchContactPicker()

Triggers the Android system contact picker UI.

expect fun launchContactPicker()

Triggers the display of the platform-specific contact picker interface.

actual fun launchContactPicker()

Displays the native iOS contact picker.

Link copied to clipboard
expect open fun methodForSelector(aSelector: COpaquePointer?): IMP?
Link copied to clipboard
expect open fun methodSignatureForSelector(aSelector: COpaquePointer?): objcnames/classes/NSMethodSignature??
Link copied to clipboard
expect open fun mutableCopy(): Any?
Link copied to clipboard
expect open override fun performSelector(aSelector: COpaquePointer?): Any?
expect open override fun performSelector(aSelector: COpaquePointer?, withObject: Any?): Any?
expect open override fun performSelector(aSelector: COpaquePointer?, withObject: Any?, _withObject: Any?): Any?
Link copied to clipboard
actual fun RegisterContactPicker(onContactSelected: (Contact?) -> Unit)

Registers the ManagedActivityResultLauncher within the Compose composition.

expect fun RegisterContactPicker(onContactSelected: (Contact?) -> Unit)

Registers the contact picker within the Compose composition.

actual fun RegisterContactPicker(onContactSelected: (Contact?) -> Unit)

Registers the callback to be invoked when a contact is selected.

Link copied to clipboard
expect open override fun respondsToSelector(aSelector: COpaquePointer?): Boolean
Link copied to clipboard
expect open override fun superclass(): ObjCClass?
Link copied to clipboard
private fun NSData.toByteArray(): ByteArray

Converts native NSData to a Kotlin ByteArray.

Link copied to clipboard
private fun UIViewController.Companion.topMostViewController(): UIViewController?

Companion extension to find the currently active UIViewController in the view hierarchy.