Skip to main content

NotificationKit

NotificationKit is the core class. It is a singleton: get it with NotificationKit.getInstance(). Most apps use the flat notifications helper instead, which delegates to this instance.

import { NotificationKit } from 'notification-kit';
const kit = NotificationKit.getInstance();

Lifecycle

MethodSignatureNotes
getInstancestatic getInstance(): NotificationKitReturns the singleton.
initinit(config: NotificationConfig): Promise<void>Detects platform, initializes the provider, wires listeners, emits ready. No-op if already initialized. Also available as static NotificationKit.init(config).
destroydestroy(): Promise<void>Removes native listeners, destroys the provider, clears listeners, resets the singleton.
isInitializedisInitialized(): boolean
getPlatformgetPlatform(): Platform'web' | 'ios' | 'android' | 'electron' | 'unknown'.
getCapabilitiesgetCapabilities(): PlatformCapabilities | null
getProvidergetProvider(): NotificationProvider | null

Permissions and token

MethodSignatureNotes
requestPermissionrequestPermission(): Promise<boolean>Provider-driven; emits permissionChanged.
checkPermissioncheckPermission(): Promise<PermissionStatus>
getTokengetToken(): Promise<string>Emits tokenReceived.

Topics

MethodSignatureNotes
subscribesubscribe(topic: string): Promise<void>Emits subscribed. With Firebase this throws (server-side only).
unsubscribeunsubscribe(topic: string): Promise<void>Emits unsubscribed.

Push and local notifications

MethodSignatureNotes
sendPushNotificationsendPushNotification(payload: PushNotificationPayload): Promise<void>Delegates to the provider; Firebase rejects client-side send.
scheduleLocalNotificationscheduleLocalNotification(options: ScheduleOptions & LocalNotificationPayload): Promise<void>Requires @capacitor/local-notifications. Emits notificationScheduled.
cancelLocalNotificationcancelLocalNotification(id: string | number): Promise<void>Id must be numeric or numeric string. Emits notificationCancelled.
getPendingLocalNotificationsgetPendingLocalNotifications(): Promise<Notification[]>
showInAppNotificationshowInAppNotification(options: InAppOptions): Promise<string>Returns the in-app id. Emits notificationShown.
isSupportedisSupported(): Promise<boolean>True if push or local notifications are available.

Channels (Android)

MethodSignatureNotes
createChannelcreateChannel(channel: NotificationChannel): Promise<void>No-op off Android. Emits channelCreated.
deleteChanneldeleteChannel(channelId: string): Promise<void>No-op off Android. Emits channelDeleted.
listChannelslistChannels(): Promise<NotificationChannel[]>Returns [] off Android.

Events

MethodSignatureNotes
onon<T extends keyof NotificationEventMap>(event: T, cb): () => voidReturns an unsubscribe function.
offoff<T>(event: T, cb?): voidOmit cb to remove all listeners for the event.

See Events for the event map.

Errors

Every method that can fail emits an error event with { error, context } and re-throws. Methods that need the kit initialized throw "NotificationKit must be initialized before use" if called before init().