Expo push notifications
Configure usePushNotifications with Expo on iOS, Android, and the web. The hook asks for permission and registers the device; expo-notifications returns an Expo push token (ExponentPushToken[…]) that you send to Expo's push service to target the device. The steps below are the one-time Expo and native platform setup that has to exist before it can run.
1.Create the Expo project
Sign in to Expo (EAS) and create a project, or reuse an existing one. Copy the project ID from the project dashboard — the provider forwards it to getExpoPushTokenAsync so the token is tied to your Expo push credentials. In a managed development build Expo can read it from app.json, but bare and production builds need it passed explicitly.
2.Install the package
Install the package and the optional Expo Notifications SDK:
pnpm add @zoharyandrianome/crosshooks expo-notificationsAdd the expo-notifications config plugin to app.json so the native projects are configured during prebuild:
{
"expo": {
"plugins": ["expo-notifications"]
}
}3.Use the hook on iOS and Android
import { usePushNotifications } from '@zoharyandrianome/crosshooks';
import { expoProvider } from '@zoharyandrianome/crosshooks/expo';
const expoPush = expoProvider({ projectId: 'your-eas-project-id' });
function NotificationsButton() {
const notifications = usePushNotifications({ provider: expoPush });
return <Button title="Enable notifications" onPress={notifications.subscribe} />;
}Keep the provider object outside the component so it stays stable. subscribe() requests permission, registers the device, and returns the Expo push token. Send that token to your backend and associate it with the signed-in user.
4.Add the Android credentials
Expo delivers to Android through Firebase Cloud Messaging. Create a Firebase project, download the google-services.json, and upload the FCM v1 service-account key to your Expo project so Expo can send on your behalf. EAS can manage this for you:
eas credentialsThen build a development or production client — push notifications don't work in Expo Go for FCM v1, so use a development build.
5.Add the iOS credentials
Apple requires every app that receives push notifications to hold a valid APNs key. EAS can generate and manage the APNs key and the Push Notifications entitlement for you:
eas credentialsBuild the app with EAS and install it on a real device — the iOS Simulator cannot receive remote push notifications.
6.Configure the web (optional)
On the web the provider rides on the browser's Push API and service worker. Configure a VAPID key for Expo's web push and register the service worker per the Expo web notifications guide, then reuse the same provider — it reports the browser subscription with platform: 'web'. If you'd rather use standards-based Web Push directly, omit the provider and usePushNotifications falls back to the browser PushManager.
7.Send securely from a backend
The hook registers the device; it does not send messages from the client. Send from a trusted backend by POSTing the stored Expo push token to Expo's push API:
curl -X POST https://exp.host/--/api/v2/push/send \
-H 'Content-Type: application/json' \
-d '{ "to": "ExponentPushToken[…]", "title": "Hello", "body": "World" }'Never expose your APNs keys or FCM service-account credentials through client environment variables. Only the Expo project ID is safe to ship in the app.