PHP code example of phnuestro / local-notifications
1. Go to this page and download the library: Download phnuestro/local-notifications library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phnuestro / local-notifications example snippets
use Phnuestro\LocalNotifications\Facades\LocalNotification;
use Phnuestro\LocalNotifications\Events\NotificationTapped;
use Native\Mobile\Attributes\OnNative;
// Ask for permission once, e.g. on first app launch or a settings screen.
LocalNotification::requestPermission();
// Fire in 10 seconds
LocalNotification::schedule('Hello!', 'Your first local notification', [
'id' => 'welcome',
'delay' => 10,
]);
// Fire at a specific time
LocalNotification::schedule('Invoice due', 'Invoice #42 is due tomorrow.', [
'id' => 'invoice-42',
'at' => now()->addDay(),
'data' => ['invoice_id' => 42],
'channelId' => 'billing',
'channelName' => 'Billing reminders',
]);
// Cancel one, or everything
LocalNotification::cancel('invoice-42');
LocalNotification::cancelAll();
// React to taps
#[OnNative(NotificationTapped::class)]
public function handleTap($id, $data = [])
{
// e.g. navigate based on $id / $data
}