Search by

smronju / nativephp-local-notifications

smronju

Schedules a one-off local notification for an exact future date and time, or a daily-repeating one, and cancels either — no server, no push, works fully offline.

Package info

github.com/smronju/nativephp-local-notifications

Language:Kotlin

Type:nativephp-plugin

pkg:composer/smronju/nativephp-local-notifications

Statistics

Installs: 54

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1.0 2026-08-16 18:14 UTC

This package is auto-updated.

Last update: 2026-09-17 19:18:09 UTC


README

Schedules a local notification — one-off at an exact future date and time, or repeating every day at the same time — and cancels either, for NativePHP Mobile. No server, no push, no network — works fully offline. iOS uses UNUserNotificationCenter; Android uses AlarmManager (exact-alarm scheduling) + a BroadcastReceiver that builds the notification directly, so it fires even if the app isn't running.

Unlike the official paid Background+Local bundle, this does exactly two things: fire a notification at a specific date and time you choose, or fire one every day at the same time — not the full dailyAt/weeklyOn cadence grammar.

Requirements

  • nativephp/mobile ^3.0 or ^4.0
  • iOS 15.0+, Android API 26+

Installation

composer require smronju/nativephp-local-notifications
php artisan vendor:publish --tag=nativephp-plugins-provider
php artisan native:plugin:register smronju/nativephp-local-notifications

Then rebuild: php artisan native:run.

Usage

use Smronju\NativephpLocalNotifications\Facades\LocalNotifications;

// Ask once, wherever makes sense in your app (e.g. the first time a user sets
// a reminder). Fire-and-forget — there's no result to branch on, since the OS
// simply won't show a notification the user never granted permission for.
LocalNotifications::requestPermission();

// Schedule — `$at` is anything implementing DateTimeInterface (Carbon included).
LocalNotifications::schedule(
    id: 'entry-01H8X...',
    title: 'Due today',
    body: 'Rent is due today',
    at: now()->addDays(3)->setTime(9, 0),
);

// Scheduling again with the same id replaces it — reschedule by just calling
// schedule() again, no need to cancel() first unless you want it gone for good.
LocalNotifications::cancel('entry-01H8X...');

// A daily reminder — `$body` is necessarily static, since nothing in your app
// re-evaluates it at fire time. Fires every day at 09:00 local time, forever,
// even if the app is never reopened after scheduling.
LocalNotifications::scheduleDaily(
    id: 'daily-overdue-reminder',
    title: 'IOU reminder',
    body: 'Check your overdue entries — open IOU now!.',
    hour: 9,
    minute: 0,
);
LocalNotifications::cancel('daily-overdue-reminder');

All calls are fire-and-forget: there's no event to listen for, because there's nothing meaningful to report back. Scheduling either succeeds or the OS silently suppresses it (no permission, alarm restricted, etc.) — either way there's no action for your app to take in response.

Notes

  • No contact with your server: this schedules against the OS, not a push service — nothing to sync, nothing that needs the device online.
  • Exact alarms on Android 12+: this plugin requests SCHEDULE_EXACT_ALARM, but on API 33+ the user must still grant "Alarms & reminders" access via system Settings — there's no runtime dialog for it. If it isn't granted, scheduling falls back to an inexact alarm rather than crashing; the notification may then arrive within a short window of the requested time rather than exactly on it.
  • Tapping a notification opens the app (its default launcher activity) — it does not deep-link anywhere specific. Handle in-app routing yourself if you need that.
  • Daily reminders have static content. Nothing queries your app's data at fire time — the title/body you pass at scheduling time is what shows every day. If you need "3 overdue items" instead of "you may have overdue items," reschedule the daily reminder with fresh text each time your app launches (still repeating daily from that point — this only refreshes the copy, not the cadence).
  • Android has no native daily-repeating exact alarm. scheduleDaily() schedules the next occurrence and the BroadcastReceiver reschedules the one after that every time it fires — so the chain only continues as long as nothing cancels it; nothing needs the app process to be running. iOS's UNCalendarNotificationTrigger(repeats: true) handles this natively with no such reschedule step.

License

MIT