Skip to main content
This page is part of Example app: a full OneSignal integration, which follows one real app from end to end. The app is Clean Beans, a cleaning rota for shared homes, built with Expo (React Native) and a Supabase backend. Everything else depends on four things being right: the SDK is installed, it starts when the app starts, each device is tied to a user, and people can control what they receive.

Install with the Expo plugin

The onesignal-expo-plugin configures the native iOS and Android projects at build time. It adds the push capability, the App Group, and the Notification Service Extension that OneSignal needs for images, badges, and confirmed delivery.
app.json

Initialize once, at the root

Clean Beans initializes OneSignal in its root layout, so it runs once on every launch before any screen appears.
app/_layout.tsx
Asking for permission on first launch is the simplest approach. To explain the benefit first, show an in-app message before the system prompt. Clean Beans has one ready: see Push permission pre-prompt.

Tie each device to a user

When someone signs in, the app passes their Supabase user ID to OneSignal.login(). That ID becomes the External ID. When they sign out, logout() detaches the device so the next person to sign in does not inherit their messages.
app/_layout.tsx
Wait for the saved session to load before calling either method. On a cold start the signed-in user is briefly unknown. If the app calls logout() at that moment and login() a moment later, the device’s push subscription can be left on an anonymous user, and pushes addressed to the External ID stop reaching the phone. Call logout() only when someone really signs out.
This one call is what makes every backend send in this guide possible. A function that knows a user’s database ID can message them without knowing anything about their devices.

Add the email channel

The app already knows each user’s email address from sign-up, so it registers it as an email subscription at sign-in. OneSignal ignores repeat calls with the same address.
src/lib/onesignalSync.ts
SMS is added the same way with addSms(), but only after the number has been verified. See SMS: verification codes and invitations.

Let people control what they get

The notification settings screen has a master switch and one switch per message type.
The notification settings screen with a master toggle and per-type toggles

Notification settings: a master switch, per-type switches, and the daily reminder time.

The master switch calls optOut() and optIn() on the push subscription, so OneSignal stops and resumes delivery to that device.
app/notification-settings.tsx
Every switch is also saved to the user’s profile row. The backend reads these columns before it sends anything, which is how per-type preferences are enforced.
src/lib/database.ts
Storing preferences in your own database, and checking them before each send, keeps the logic in one place. The alternative is to store them as tags and filter by tag in OneSignal. That works well when you send to segments. Clean Beans sends to specific users, so checking the database is simpler.

Mobile SDK reference

Every client method used in this guide.

Users and External IDs

How identity links subscriptions across channels and devices.