voicecode-bv / nativephp-badge
Set the app icon badge counter from JS/PHP for NativePHP Mobile
Package info
github.com/voicecode-bv/nativephp-badge
Language:Kotlin
Type:nativephp-plugin
pkg:composer/voicecode-bv/nativephp-badge
Requires
- php: ^8.2
- nativephp/mobile: ^3.0
README
A small NativePHP Mobile plugin that sets the app icon badge counter (the red number on the app icon) from JavaScript.
Installation
composer require voicecode-bv/nativephp-badge
The 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', ),
// tsconfig.json "paths": { "@voicecode-bv/nativephp-badge": ["./vendor/voicecode-bv/nativephp-badge/resources/js/index.ts"] }
Why
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.
Usage (JS)
import { setBadge } from '@voicecode-bv/nativephp-badge'; await setBadge(3); // show "3" on the app icon await setBadge(0); // clear the badge
Platform notes
- 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.
Bridge function
| Name | Params | Returns |
|---|---|---|
Badge.Set |
{ count: int } |
{ success: bool } |
License
The MIT License (MIT). See LICENSE. Copyright (c) Voicecode BV.