Capacitor Integration
Integrate Entrig in 5 steps:
Install → Setup (iOS only) → Initialize → Register → Handle
Installation
npm install @entrig/capacitornpx cap syncPlatform Setup
Android
No additional setup required.
iOS
Run the setup command from your project root:
npx @entrig/capacitor setup iosThis configures AppDelegate.swift, App.entitlements, and Info.plist with the required push notification settings.
Initialization
import { Entrig } from '@entrig/capacitor';
await Entrig.init({ apiKey: 'YOUR_ENTRIG_API_KEY' });Your API key is available in the Entrig dashboard under project settings.
Registering Devices
Call Entrig.register() with the user’s ID when they sign in, and Entrig.unregister() when they sign out.
// On sign inawait Entrig.register({ userId: userId });
// On sign outawait Entrig.unregister();The userId you pass here must match the user identifier field configured in your notification in the Entrig dashboard. If they do not match, Entrig cannot resolve the recipient.
We recommend using the Supabase Auth user ID (session.user.id) as the userId. It is stable, always available when using Supabase Auth, and is typically the ID that other tables in your database already reference.
Handling Notifications
When a notification arrives, your app can be in one of three states:
- Foreground - app is open and visible
- Background - app is running but not visible
- Terminated - app is fully closed
Entrig handles displaying notifications in all three states. The only thing you need to handle is what happens when the user taps a notification.
To handle notification taps:
Entrig.addListener('onNotificationOpened', (event) => { // navigate based on event.data});If the app was fully terminated when the notification was tapped, use getInitialNotification() on startup instead:
const notification = await Entrig.getInitialNotification();if (notification) { // app was launched by tapping a notification}By default, notifications are also shown as a banner when the app is in the foreground. You can turn this off:
await Entrig.init({ apiKey: 'YOUR_ENTRIG_API_KEY', showForegroundNotification: false,});If you need to respond to a notification arriving while the app is open (e.g. show an in-app banner):
Entrig.addListener('onForegroundNotification', (event) => { // event.title, event.body, event.data});NotificationEvent fields:
| Field | Description |
|---|---|
title | Notification title |
body | Notification body |
data | Custom payload data from your database |
Permission Handling
By default, register() requests notification permission automatically. To handle permissions yourself:
await Entrig.init({ apiKey: 'YOUR_ENTRIG_API_KEY', handlePermission: false,});
// Then request manually before registeringconst { granted } = await Entrig.requestPermission();if (granted) { await Entrig.register({ userId: userId });}