Overview
Push notifications allow you to engage users even when your app isn’t running. Expo providesexpo-notifications to handle both local and remote notifications across iOS and Android.
Installation
1
Install the package
2
Configure your app.json
Add notification configuration to your
app.json:app.json
3
Request permissions
Create a hook to manage notification permissions:
hooks/useNotifications.ts
Handling Notifications
Configure notification behavior
Set how notifications are displayed when the app is foregrounded:App.tsx
Listen for notifications
- Foreground
- Background/Quit
Sending Notifications
Local notifications
Push notifications from your server
- Node.js
- Python
Platform-Specific Setup
- iOS - APNs
- Android - FCM
Apple Push Notification Service
1
Create an APNs key
- Go to Apple Developer Portal
- Create a new key with Push Notifications enabled
- Download the
.p8file
2
Upload to Expo
3
Enable push notifications capability
In your
app.json:Notification Channels (Android)
Android 8.0+ requires notification channels:Testing Notifications
Test with Expo push tool
Use the Expo Push Notification Tool to send test notifications:- Get your Expo push token from your app
- Enter it in the tool
- Compose and send a test notification
Test locally
Troubleshooting
Notifications not received on iOS
Notifications not received on iOS
- Ensure you’re testing on a physical device (not simulator)
- Check that APNs credentials are correctly configured
- Verify push notifications capability is enabled
- Check that your app is properly signed
Notifications not showing when app is foregrounded
Notifications not showing when app is foregrounded
Make sure you’ve set up the notification handler:
Push token not generating
Push token not generating
- Verify you’re using a physical device
- Check that all permissions are granted
- For iOS: Ensure APNs is properly configured
- For Android: Verify google-services.json is present
Sound not playing
Sound not playing
- Ensure the sound file is in the correct format (WAV or MP3)
- Add the sound file to your assets and reference it in app.json
- For Android, set up the notification channel with the sound
Best Practices
- Request permission contextually: Ask for notification permissions when the user takes an action that benefits from notifications
- Use notification channels: Create separate channels for different types of notifications on Android
- Include deep links: Add data to notifications to navigate users to relevant content
- Handle notification lifecycle: Listen for notifications in all app states (foreground, background, quit)
- Test thoroughly: Test on both iOS and Android physical devices
- Store tokens securely: Send push tokens to your backend and associate them with user accounts
- Handle token refresh: Listen for token updates and update your backend
- Badge management: Clear badges when appropriate using
Notifications.setBadgeCountAsync(0)