|
| 1 | +--- |
| 2 | +title: APIs |
| 3 | +order: 4 |
| 4 | +--- |
| 5 | + |
| 6 | +# API Reference |
| 7 | + |
| 8 | +Complete documentation for all NativePHP Mobile APIs. Each API provides access to native device capabilities through familiar PHP facades. |
| 9 | + |
| 10 | +## Available APIs |
| 11 | + |
| 12 | +### [Biometrics](/docs/mobile/1/apis/biometrics) |
| 13 | +**Face ID, Touch ID, Fingerprint Authentication** |
| 14 | +```php |
| 15 | +Biometrics::promptForBiometricID(); |
| 16 | +``` |
| 17 | +Secure user authentication using device biometric sensors. Supports Face ID on iOS, Touch ID, and fingerprint readers on Android. |
| 18 | + |
| 19 | +### [Camera](/docs/mobile/1/apis/camera) |
| 20 | +**Photo Capture & Gallery Access** |
| 21 | +```php |
| 22 | +Camera::getPhoto(); |
| 23 | +Camera::pickImages('images', true, 5); |
| 24 | +``` |
| 25 | +Take photos with the device camera or select images from the photo gallery. Supports both single and multiple image selection. |
| 26 | + |
| 27 | +### [Dialog](/docs/mobile/1/apis/dialog) |
| 28 | +**Native UI Elements** |
| 29 | +```php |
| 30 | +Dialog::alert('Title', 'Message', $buttons, $callback); |
| 31 | +Dialog::toast('Success message'); |
| 32 | +Dialog::share('Title', 'Text', 'https://example.com'); |
| 33 | +``` |
| 34 | +Display native alerts, toast notifications, and sharing interfaces that match platform design guidelines. |
| 35 | + |
| 36 | +### [Geolocation](/docs/mobile/1/apis/geolocation) ⭐ New in v1.1 |
| 37 | +**GPS & Location Services** |
| 38 | +```php |
| 39 | +Geolocation::getCurrentPosition(true); // High accuracy |
| 40 | +Geolocation::checkPermissions(); |
| 41 | +Geolocation::requestPermissions(); |
| 42 | +``` |
| 43 | +Access device location services with configurable accuracy levels and proper permission handling. |
| 44 | + |
| 45 | +### [Haptics](/docs/mobile/1/apis/haptics) |
| 46 | +**Vibration & Tactile Feedback** |
| 47 | +```php |
| 48 | +Haptics::vibrate(); |
| 49 | +``` |
| 50 | +Provide tactile feedback for user interactions, form validation, and important events. |
| 51 | + |
| 52 | +### [PushNotifications](/docs/mobile/1/apis/push-notifications) |
| 53 | +**Firebase Cloud Messaging** |
| 54 | +```php |
| 55 | +PushNotifications::enrollForPushNotifications(); |
| 56 | +PushNotifications::getPushNotificationsToken(); |
| 57 | +``` |
| 58 | +Register devices for push notifications and manage FCM tokens for server-side notification delivery. |
| 59 | + |
| 60 | +### [SecureStorage](/docs/mobile/1/apis/secure-storage) ⭐ New in v1.1 |
| 61 | +**Keychain & Keystore Operations** |
| 62 | +```php |
| 63 | +SecureStorage::set('api_token', $token); |
| 64 | +$token = SecureStorage::get('api_token'); |
| 65 | +SecureStorage::delete('api_token'); |
| 66 | +``` |
| 67 | +Store sensitive data securely using iOS Keychain and Android Keystore with automatic encryption. |
| 68 | + |
| 69 | +### [System](/docs/mobile/1/apis/system) |
| 70 | +**System Functions & Legacy API** |
| 71 | +```php |
| 72 | +System::flashlight(); // Toggle flashlight |
| 73 | +``` |
| 74 | +Control system functions like the flashlight. Also provides deprecated methods that have moved to dedicated facades. |
| 75 | + |
| 76 | +## API Patterns |
| 77 | + |
| 78 | +### Synchronous APIs |
| 79 | +Execute immediately and return results: |
| 80 | +- `Haptics::vibrate()` |
| 81 | +- `System::flashlight()` |
| 82 | +- `Dialog::toast()` |
| 83 | +- `SecureStorage::set()` / `get()` |
| 84 | + |
| 85 | +### Asynchronous APIs |
| 86 | +Trigger operations and fire events when complete: |
| 87 | +- `Camera::getPhoto()` → `PhotoTaken` event |
| 88 | +- `Biometrics::promptForBiometricID()` → `Completed` event |
| 89 | +- `PushNotifications::enrollForPushNotifications()` → `TokenGenerated` event |
| 90 | +- `Geolocation::getCurrentPosition()` → `LocationReceived` event |
| 91 | + |
| 92 | +### Event Handling |
| 93 | +All async APIs use Laravel events with Livewire integration: |
| 94 | + |
| 95 | +```php |
| 96 | +use Livewire\Attributes\On; |
| 97 | +use Native\Mobile\Events\Camera\PhotoTaken; |
| 98 | + |
| 99 | +#[On('native:' . PhotoTaken::class)] |
| 100 | +public function handlePhotoTaken(string $path) |
| 101 | +{ |
| 102 | + // Process the captured photo |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +## Migration from System Facade |
| 107 | + |
| 108 | +Many methods have moved from the `System` facade to dedicated facades in v1.1: |
| 109 | + |
| 110 | +| Old (Deprecated) | New (Recommended) | |
| 111 | +|------------------|-------------------| |
| 112 | +| `System::camera()` | `Camera::getPhoto()` | |
| 113 | +| `System::vibrate()` | `Haptics::vibrate()` | |
| 114 | +| `System::promptForBiometricID()` | `Biometrics::promptForBiometricID()` | |
| 115 | +| `System::enrollForPushNotifications()` | `PushNotifications::enrollForPushNotifications()` | |
| 116 | +| `System::secureSet()` / `secureGet()` | `SecureStorage::set()` / `get()` | |
| 117 | + |
| 118 | +The old methods still work but are deprecated. See the [System API documentation](/docs/mobile/1/apis/system) for complete migration guidance. |
| 119 | + |
| 120 | +## Platform Support |
| 121 | + |
| 122 | +All APIs work on both iOS and Android with platform-appropriate implementations: |
| 123 | +- **iOS**: Uses native iOS frameworks and APIs |
| 124 | +- **Android**: Uses Android SDK and native libraries |
| 125 | +- **Permissions**: Automatically handled with user prompts when required |
| 126 | +- **Fallbacks**: Graceful degradation when features aren't available |
| 127 | + |
| 128 | +## Error Handling |
| 129 | + |
| 130 | +APIs provide both success and error events for proper error handling: |
| 131 | + |
| 132 | +```php |
| 133 | +#[On('native:' . PhotoTaken::class)] |
| 134 | +public function handleSuccess($data) { /* ... */ } |
| 135 | + |
| 136 | +#[On('native:' . PermissionDenied::class)] |
| 137 | +public function handleError($error) { /* ... */ } |
| 138 | +``` |
| 139 | + |
| 140 | +Each API documentation includes complete error handling examples and best practices. |
0 commit comments