Skip to main content

Installation


Methods

Methods

Register for push (custom setups only)

Despia requests push permission and registers the device with OneSignal automatically at app launch. You do not need to call this. It is only available if you have disabled auto-registration in the Despia dashboard and want to trigger the permission prompt at a specific point in your own flow.

Associates the device with your user. Call this on every authenticated app load, immediately after you confirm the user is logged in. This is how OneSignal knows which device to deliver a notification to when you send it.
The value you pass here is what you include in include_external_user_ids when sending notifications from your backend.

Check push permission status

Check whether the user has push notifications enabled on their device. Use this to show an in-app prompt directing them to their settings if they have not granted permission.
A good pattern is to check on every app load and show a non-intrusive banner when push is disabled, rather than blocking the user. settingsapp:// opens the device settings page for your app where the user can enable notifications directly.

Full client-side setup


Backend: send a notification

Send notifications from your backend using OneSignal’s REST API. Use include_external_user_ids to target specific users by the same ID you passed to setonesignalplayerid://.

Send to multiple users

Send to all users


Notification payload options


Deep linking and routing from a notification

The data object supports three fields for routing and state delivery. All are optional and can be combined freely.

Sending a path from your backend

Despia applies the path via the History API on notification tap. Most SPA routers react to the popstate event and navigate automatically, no additional code required on the web side.

window.onNotificationEvent (optional)

If your router does not react to a synthetic popstate, or you need to act on metadata, define window.onNotificationEvent at the top of your entry bundle. The host app calls it on every notification tap after applying the URL change.
Payload shape:
If you set metadata via the OneSignal dashboard Additional Data fields, the value arrives as a string and must be JSON.parsed. If you send metadata as a real JSON object via the REST API data field, the handler receives an object directly. path and url are always strings.

Timing

The event is delivered once per tap and then cleared.

Critical alerts

Critical alerts bypass Do Not Disturb and silent mode on the user’s device.

iOS

iOS requires the Critical Alerts entitlement from Apple. Request it at developer.apple.com/contact/request/notifications-critical-alerts-entitlement. Apple reviews requests manually and approval can take several weeks. When submitting the request, you need to enable the entitlement on two bundle IDs, your core app bundle ID and your OneSignal Service Extension bundle ID. For example, if your app bundle ID is com.despia.myapp, add both:
  • com.despia.myapp
  • com.despia.myapp.OneSignalNotificationServiceExtension
Once Apple approves the request, enable critical alerts in Despia > App > Integrations > OneSignal > Critical Alerts and rebuild a new version in Despia. After the rebuild, set ios_critical_alert to 1 in your payload.

Android

No dashboard configuration or rebuild is required. Set priority to 10 and android_channel_id to a high-importance channel in your OneSignal payload. To get your channel ID, go to OneSignal > Settings > Messaging > Android Categories and create a new category with importance set to Urgent. OneSignal will generate a channel ID for that category, copy it and use it as android_channel_id in your payload.

Both platforms

To send a single critical alert that works on both Android and iOS, combine the fields in one payload.

Segmentation

Beyond include_external_user_ids, OneSignal supports segments based on user behaviour. Set tags on users to create custom segments.

Resources

NPM Package

despia-native

OneSignal Dashboard

Configure your push notification app

Create Notification API

Full OneSignal REST API reference