A small NativePHP Mobile plugin that sets the app icon badge counter (the red number on the app icon) from JavaScript.
composer require voicecode-bv/nativephp-badgeThe JS bridge is published under the @voicecode-bv/nativephp-badge import. Point your
bundler at it (the package is installed into vendor/voicecode-bv/nativephp-badge):
// vite.config.ts
'@voicecode-bv/nativephp-badge': path.resolve(
__dirname,
'vendor/voicecode-bv/nativephp-badge/resources/js/index.ts',
),iOS sets the icon badge automatically from the aps.badge field of an incoming
push payload, but it does not decrement the badge when the user reads
notifications inside the app. This plugin exposes a Badge.Set bridge function
so the SPA can keep the badge in sync with the unread-notifications count.
import { setBadge } from '@voicecode-bv/nativephp-badge';
await setBadge(3); // show "3" on the app icon
await setBadge(0); // clear the badge- iOS: sets the exact badge number via
UNUserNotificationCenter.setBadgeCount. - Android: numeric icon badges are launcher-dependent with no reliable
launcher-agnostic API.
Badge.Setonly handles clearing (count0, viaNotificationManager.cancelAll()); positive counts are a no-op and rely on the FCM push payload'snotification_count.
| Name | Params | Returns |
|---|---|---|
Badge.Set |
{ count: int } |
{ success: bool } |
The MIT License (MIT). See LICENSE. Copyright (c) Voicecode BV.