The push notification service has been completely refactored to use Firebase Cloud Messaging (FCM) and Notifee exclusively, removing the dependency on Expo Notifications. This provides better native support, more reliable notification delivery, and enhanced features for both iOS and Android platforms.
expo-notifications- No longer used for notification handling
@react-native-firebase/messaging- Primary package for push notifications@notifee/react-native- For advanced Android notification channels and iOS notification management
- Migrated from
Notifications.setNotificationChannelAsync()tonotifee.createChannel() - Improved channel properties with better Android 13+ support
- Maintains all 32 notification channels (standard + custom call tones)
-
iOS: Uses
messaging().requestPermission()with support for:- Standard notifications (alert, badge, sound)
- Critical Alerts - Emergency notifications that bypass Do Not Disturb
- Provisional authorization
-
Android: Uses both FCM and Notifee permission systems
- FCM for push token management
- Notifee for notification channel permissions
The service now handles three types of notifications:
-
Foreground Messages:
- Handled via
messaging().onMessage() - Shows notification modal when app is open
- Processes eventCode for navigation
- Handled via
-
Background Messages:
- Handled via
messaging().setBackgroundMessageHandler() - Processes data payloads when app is in background
- System displays notifications automatically if payload includes notification object
- Handled via
-
Notification Taps:
messaging().onNotificationOpenedApp()- App in backgroundmessaging().getInitialNotification()- App was killed- Both trigger modal display for eventCode-based navigation
- FCM tokens obtained via
messaging().getToken() - Automatic token refresh handled by Firebase SDK
- Token registration with backend continues to work seamlessly
- Platform detection (iOS=1, Android=2) maintained
await pushNotificationService.initialize();- Sets up Android notification channels
- Registers background message handler
- Establishes foreground message listener
- Sets up notification tap handlers
pushNotificationService.cleanup();- Unsubscribes from all FCM listeners
- Cleans up resources properly
- Safe to call multiple times
The service maintains integration with the usePushNotificationModalStore for handling notification events:
// Notification data structure
{
eventCode: string, // Required for modal display
title?: string,
body?: string,
data: Record<string, unknown>
}Event codes trigger different app behaviors:
C:*- Call notificationsM:*- Message notificationsT:*- Chat notificationsG:*- Group notifications
The public API remains unchanged:
// Hook usage (unchanged)
const { pushToken } = usePushNotifications();
// Manual registration (unchanged)
const token = await pushNotificationService.registerForPushNotifications(
unitId,
departmentCode
);
// Get current token (unchanged)
const token = pushNotificationService.getPushToken();The service continues to work with existing stores:
usePushNotificationModalStore- For displaying notification modalsuseCoreStore- For active unit trackingsecurityStore- For department rights
- Critical alert support for emergency notifications
- Proper authorization status handling
- Support for provisional authorization
- Badge and sound management
- Rich notification channels with custom sounds
- Vibration patterns per channel
- High importance for emergency calls
- LED light colors and lockscreen visibility
- Android 13+ notification permission support
Comprehensive test coverage includes:
-
Notification Handling Tests
- Call notifications with eventCode
- Message notifications
- Chat and group notifications
- Edge cases (empty eventCode, missing data, non-string eventCode)
-
Listener Management Tests
- Initialization verification
- Cleanup verification
- Multiple cleanup calls
- Cleanup without initialization
-
Registration Tests
- Successful registration
- Permission request flow
- Permission denial handling
- Token retrieval
-
Android Channel Tests
- Verifies all 32 channels are created
- Platform-specific behavior
All tests passing: 1421 tests passed
No code changes required in components using the push notification service. The refactor is fully backward compatible.
-
Ensure Firebase configuration files are present:
google-services.json(Android)GoogleService-Info.plist(iOS)
-
Verify native dependencies are installed:
cd ios && pod install cd android && ./gradlew clean
-
Test push notifications on both platforms in:
- Foreground state
- Background state
- Killed/terminated state
- Reliability: FCM is the native push notification service for both platforms
- Features: Access to platform-specific features (critical alerts, rich notifications)
- Performance: Better battery optimization and delivery guarantees
- Maintenance: Aligned with platform best practices and future updates
- Debugging: Better logging and error handling with Firebase console integration
Potential improvements enabled by this refactor:
- Rich notifications with images and actions
- Notification grouping and bundling
- Custom notification layouts (Android)
- Notification scheduling with Notifee
- Enhanced analytics via Firebase Analytics integration
- A/B testing for notification content