Understanding the app lifecycle and responding to native events
NativePHP Mobile dispatches Laravel events throughout the app lifecycle and when native features are used. This allows your application to respond to device-level events just like any other Laravel event.
Use the #[On] attribute to listen in Livewire components:
use Livewire\Component;use Livewire\Attributes\On;use Native\Mobile\Events\Camera\PhotoTaken;class PhotoUploader extends Component{ #[On('native:Native\\Mobile\\Events\\Camera\\PhotoTaken')] public function photoTaken($path, $mimeType, $id) { // Handle the photo $this->uploadPhoto($path); }}
Notice the native: prefix and double-escaped backslashes when using the #[On] attribute with NativePHP events.
Dispatched when an app update is installed on the device.
namespace Native\Mobile\Events\App;class UpdateInstalled{ public function __construct( public readonly string $version, public readonly int $timestamp ) {}}
namespace Native\Mobile\Events\Camera;class PhotoTaken{ public function __construct( public string $path, public string $mimeType = 'image/jpeg', public ?string $id = null ) {}}
namespace Native\Mobile\Events\Camera;class VideoRecorded{ public function __construct( public string $path, public string $mimeType = 'video/mp4', public ?string $id = null ) {}}
namespace Native\Mobile\Events\Scanner;class CodeScanned{ public function __construct( public string $data, public string $format, public ?string $id = null ) {}}
Dispatched when location data is received from the device.
namespace Native\Mobile\Events\Geolocation;class LocationReceived{ public function __construct( public bool $success, public ?float $latitude = null, public ?float $longitude = null, public ?float $accuracy = null, public ?int $timestamp = null, public ?string $provider = null, public ?string $error = null, public ?string $id = null ) {}}
namespace Native\Mobile\Events\Geolocation;class PermissionRequestResult{ public function __construct( public bool $granted, public ?string $id = null ) {}}
Dispatched when checking current location permission status.
namespace Native\Mobile\Events\Geolocation;class PermissionStatusReceived{ public function __construct( public bool $granted, public ?string $id = null ) {}}
Dispatched when a user taps a button in a native alert dialog.
namespace Native\Mobile\Events\Alert;class ButtonPressed{ public function __construct( public int $index, public string $label, public ?string $id = null ) {}}
Dispatched after biometric authentication attempt.
namespace Native\Mobile\Events\Biometric;class Completed{ public function __construct( public bool $success, public ?string $error = null, public ?string $id = null ) {}}
Dispatched when a push notification token is generated.
namespace Native\Mobile\Events\PushNotification;class TokenGenerated{ public function __construct( public string $token, public ?string $id = null ) {}}
Most events include an optional $id parameter. Use this to track which action triggered the event when you have multiple instances:
// Trigger camera with IDCamera::takePhoto(['id' => 'profile-photo']);// Listen for that specific photo#[On('native:Native\\Mobile\\Events\\Camera\\PhotoTaken')]public function photoTaken($path, $mimeType, $id){ if ($id === 'profile-photo') { $this->updateProfilePhoto($path); }}