Notifications & badges
Check authorization, ask for push permission, open settings, and set the app-icon badge.
Check notification status
Examples reuse the single browser client from Set up the client. Adjust the ~/lib/bdk import to your app’s path; do not create a client in each component or handler.
Critical alerts and time-sensitive notifications are not available today. Do not offer controls to enable them.
Read the current notification authorization. The response also includes time-sensitive and critical-alert status fields; these fields do not mean those features are available to customers.
In a plain browser the call resolves ok: false with a code such as common/feature_disabled. Branch on !result.ok.
Ask for push permission
Read the current push authorization, then request it. granted is true for both granted and provisional. mode is the app's prompt timing: automatic asks when the app opens; manual never asks until you call request(), so show your own explainer first. Read it from status() — it can change without an app update. Call request() after await bdk.ready(), from a user tap.
This feature can be switched off in a given app build. Check await bdk.capabilities.has("push.prompt") before showing the UI. When it is off, the call resolves ok: false with code: "common/feature_disabled". See Detect features.
Open notification settings
Send the user to the OS notification settings after a denial. notifications.openSettings() opens the general settings; push.openSettings() provides the same task from the push-prompt namespace.
Critical alerts and time-sensitive notifications
Critical alerts and time-sensitive notifications are not available today. The SDK exposes related types and helpers, but customers cannot enable these features.
Set the app badge
Read, set, or clear the app-icon badge. iOS sets an exact count. Android set is unsupported (ok: false, code: "common/unsupported_platform"); get is an approximate count of active notifications (source: "active_notifications", approximate: true). clear works on both — on Android it reports how many cancellable notifications were removed.
Pass a finite non-negative integer to set. Check canSet() before offering a setter.
This feature can be switched off in a given app build. Check await bdk.capabilities.has("badge") before showing the UI. When it is off, the call resolves ok: false with code: "common/feature_disabled". See Detect features.
Associate a device with a signed-in user
After sign-in, wait for device info and send playerId to your authenticated backend. Subscribe to deviceInfo before reading the initial value so changes are not missed. Reconcile a changed or null ID; remove the user-device association on sign-out. Remove this page’s listener when its UI unmounts. Push-off apps report null. Your server selects eligible recipients; do not trust a browser’s list of other users’ device IDs.
BDK Preview uses BDK’s OneSignal account. Test your server’s targeted sends in your own app build.
React to permission changes
Refresh status after the user answers a prompt or returns from Settings. permissions.changed fires when a tracked permission changes — not on the first snapshot — so subscribe before you call request or openSettings.
Handle notification taps
Use push.onClick for live taps and retained cold-start taps. It returns an unsubscribe function; call it when this UI unmounts. Replayed taps are deduplicated by notification id and action id. Each click is a BdkPushClickRecord.
Check capabilities.has("push.click") before offering tap handling. Treat notification data as input: validate the destination and check the signed-in account’s access before opening protected content.
Read retained notification taps
push.getPendingClicks() drains retained clicks, newest first. Use it for manual handling instead of onClick replay. For live events alone, subscribe with bdk.on("push.clicked", listener); it does not provide the helper’s retained-click replay.