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.
// Only for custom setups with auto-registration disableddespia('registerpush://')
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.
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.
const result = await despia('checkNativePushPermissions://', ['nativePushEnabled'])if (result.nativePushEnabled) { // Push is enabled , proceed normally} else { // Push is disabled , show a prompt explaining why notifications matter // and offer a button to open device settings despia('settingsapp://')}
Return key
Type
Description
nativePushEnabled
boolean
true if the user has granted push permission, false if denied or not yet requested
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.
import despia from 'despia-native'const isDespia = navigator.userAgent.toLowerCase().includes('despia')async function initNotifications(userId) { if (!isDespia) return // Link device to your user , call on every authenticated load despia(`setonesignalplayerid://?user_id=${userId}`)}// Call on every authenticated loadinitNotifications(currentUser.id)
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://.
await sendPushNotification( ['user_123', 'user_456', 'user_789'], 'New message', 'You have a new message waiting')// change include_external_user_ids to an array of user IDs
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:
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.
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.
To navigate the WebView to a specific page when a user taps a notification, add a url key inside the data field of the OneSignal REST API payload.
body: JSON.stringify({ app_id: process.env.ONESIGNAL_APP_ID, include_external_user_ids: [userId], headings: { en: 'You have a new message' }, contents: { en: 'Tap to view it' }, data: { url: 'https://yourapp.com/messages/123' // opened in the WebView on tap },})