PushNotifications
NativePHP for Desktop and Mobile have reached v1!
On this page
#Overview
The PushNotifications API handles device registration for Firebase Cloud Messaging to receive push notifications.
Copied!
use Native\Mobile\Facades\PushNotifications;
#Methods
#enrollForPushNotifications()
Requests permission and enrolls the device for push notifications.
Returns: void
#getPushNotificationsToken()
Retrieves the current FCM token for this device.
Returns: string|null
- The FCM token, or null
if not available
#Events
#TokenGenerated
Fired when a push notification token is successfully generated.
Payload: string $token
- The FCM token for this device
Copied!
use Livewire\Attributes\On;use Native\Mobile\Events\PushNotification\TokenGenerated; #[On('native:'.TokenGenerated::class)]public function handlePushToken(string $token){ // Send token to your backend $this->sendTokenToServer($token);}
#Permission Flow
- User taps "Enable Notifications"
- App calls
enrollForPushNotifications()
- System shows permission dialog
- If granted, FCM generates token
TokenGenerated
event fires with token- App sends token to backend
- Backend stores token for user
- Server can now send notifications to this device
#Best Practices
- Request permission at the right time (not immediately on app launch)
- Explain the value of notifications to users
- Handle permission denial gracefully