MobileContacts Plugin for NativePHP Mobile#
A NativePHP plugin for native contacts integration on iOS (Contacts framework) and Android (ContactsContract).
Installation#
Copied!
composer require srwiez/nativephp-mobile-contactsphp artisan vendor:publish --tag=nativephp-plugins-providerphp artisan native:plugin:register srwiez/nativephp-mobile-contacts
Usage#
Copied!
use SRWieZ\NativePHP\Mobile\Contacts\Facades\MobileContacts;use SRWieZ\NativePHP\Mobile\Contacts\Data\ContactData;use SRWieZ\NativePHP\Mobile\Contacts\Data\PhoneNumber;use SRWieZ\NativePHP\Mobile\Contacts\Data\EmailAddress; // Request permission$result = MobileContacts::requestAccess(); // Query contacts$contacts = MobileContacts::contacts() ->search('John') ->withPhoneNumber() ->limit(50) ->get(); // Create a contact$contact = MobileContacts::createContact( ContactData::make() ->name('John', 'Doe') ->organization('Acme Inc') ->addPhone(PhoneNumber::mobile('+1234567890'))); // Update a contact$contact->update( ContactData::make()->jobTitle('Senior Developer')); // Delete a contact$contact->delete();
Manage Contact Access#
Open the iOS 18+ contact access picker to let users manage which contacts your app can access in limited-access mode. The call is asynchronous — it returns immediately and dispatches a ContactAccessUpdated event when the user finishes.
Copied!
use SRWieZ\NativePHP\Mobile\Contacts\Facades\MobileContacts; $success = MobileContacts::manageContactAccess(); // true if picker was presented
Platform behavior:
- iOS 18+ — Opens
contactAccessPicker, allowing the user to select multiple contacts in limited-access mode. - iOS < 18 — Returns
falsewith an error (Contact access picker requires iOS 18.0 or later). - Android — Not available (iOS-only feature).
JavaScript:
Copied!
import { mobileContacts } from '@srwiez/nativephp-mobile-contacts'; await mobileContacts.manageContactAccess();
Listening for Events#
Copied!
use Native\Mobile\Attributes\OnNative;use SRWieZ\NativePHP\Mobile\Contacts\Events\ContactCreated;use SRWieZ\NativePHP\Mobile\Contacts\Events\ContactAccessUpdated; #[OnNative(ContactCreated::class)]public function handleContactCreated($contactId, $displayName){ // Contact was created} #[OnNative(ContactAccessUpdated::class)]public function handleContactAccessUpdated($identifiers, $contacts, $count, $timestamp){ // $identifiers — array of native contact IDs the user selected // $contacts — array of full contact data for each selected contact // $count — number of contacts updated // $timestamp — Unix timestamp of the selection}
Available Events#
| Event | Parameters |
|---|---|
ContactAccessGranted |
— |
ContactAccessDenied |
— |
ContactCreated |
$contactId, $displayName |
ContactUpdated |
$contactId, $displayName |
ContactDeleted |
$contactId |
ContactAccessUpdated |
$identifiers, $contacts, $count, $timestamp |
GroupCreated |
$groupId, $name |
GroupDeleted |
$groupId |
All events live in the SRWieZ\NativePHP\Mobile\Contacts\Events namespace.
Version Support#
| Platform | Minimum Version |
|---|---|
| Android | 5.0 (API 21) |
| iOS | 18.0 |
Features requiring higher versions:
- iOS 18+:
manageContactAccess()contact access picker for limited-access mode
Support#
Bugs, questions, and feature requests should be reported at github.com/SRWieZ/nativephp-mobile-packages.