Search by

smronju / nativephp-contacts-picker

smronju

Presents the system contact picker for NativePHP Mobile and returns the chosen contact's name and phone number — no contacts permission required.

Package info

github.com/smronju/nativephp-contacts-picker

Type:nativephp-plugin

pkg:composer/smronju/nativephp-contacts-picker

Statistics

Installs: 8

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1.0 2026-08-20 12:17 UTC

This package is auto-updated.

Last update: 2026-08-20 12:17:29 UTC


README

Presents the system contact picker (iOS: CNContactPickerViewController, Android: the system contacts picker via ACTION_PICK) for NativePHP Mobile and returns the chosen contact's display name and phone number.

Both platforms' system pickers mediate access without your app ever holding contacts permission, so this plugin declares none — no permission prompt appears.

Requirements

  • nativephp/mobile ^3.0 or ^4.0
  • iOS 15.0+, Android API 21+

Installation

composer require smronju/nativephp-contacts-picker
php artisan vendor:publish --tag=nativephp-plugins-provider
php artisan native:plugin:register smronju/nativephp-contacts-picker

Then rebuild: php artisan native:run.

Usage

use Smronju\NativephpContactsPicker\Facades\ContactsPicker;

ContactsPicker::pick();

pick() is fire-and-forget: it only presents the picker. The result arrives asynchronously via the ContactPicked event once the user finishes — picking a contact can take arbitrarily long, so it can't be this call's return value.

Listening for the Result

use Native\Mobile\Attributes\On;
use Smronju\NativephpContactsPicker\Events\ContactPicked;

#[On(ContactPicked::class)]
public function handleContactPicked(?string $name = null, ?string $phone = null): void
{
    if ($name !== null) {
        $this->person = $name;
    }

    if ($phone !== null) {
        $this->phone = $phone;
    }
}

$name and $phone are both null when the user cancels rather than picks someone. $phone is also null on a real pick when the chosen contact has no phone number saved at all; when it does, it's the first number on file — the picker itself doesn't ask which to use.

Each = null default on the listener parameters matters, even though the types are already nullable: NativePHP's native-event dispatcher only supplies an argument for payload keys actually present, and this plugin omits a key entirely rather than sending an explicit null (sending an explicit null would arrive as '', not null — the dispatcher casts any present value to the parameter's declared type, and PHP's (string) null is ''). Without its own default, a listener parameter for an omitted key gets no argument at all and throws ArgumentCountError.

License

MIT