Interview frequency: …
Short answer
Use expo-notifications or Notifee to request user permission, obtain the device's Push Token and send it to the server, and listen for notification taps to navigate directly to a screen.
Explanation
Notifications require APNs certificates for iOS and Firebase Cloud Messaging (FCM) for Android. On app startup, request notification permission, obtain the unique Expo Push Token, and store it in the server database with the user's account. Handle opening the app from a notification with addNotificationResponseReceivedListener.
Code example
import * as Notifications from 'expo-notifications';
async function registerForPushNotifications(): Promise<string | null> {
const { status } = await Notifications.requestPermissionsAsync();
if (status !== 'granted') return null;
const tokenData = await Notifications.getExpoPushTokenAsync();
return tokenData.data; // Send this token to the Backend
}Common mistakes
- Ignoring required notification channel setup on Android, which can prevent notifications from appearing or playing alert sounds.