Challenge - 5 Problems
Push Notifications Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate1:30remaining
What happens when a notification is received while the app is in the foreground?
Using expo-notifications, what is the default behavior when a push notification arrives while the app is open and active on the screen?
Attempts:
2 left
💡 Hint
Think about how notifications behave when the user is already using the app.
✗ Incorrect
By default, expo-notifications does not show system alerts for notifications received in the foreground. Instead, the app receives the notification data silently, allowing custom handling.
🧠 Conceptual
intermediate1:00remaining
Which permission is required to receive push notifications on iOS?
To receive push notifications on an iOS device using expo-notifications, which permission must the app request from the user?
Attempts:
2 left
💡 Hint
Think about what permission controls alerts and badges on iOS.
✗ Incorrect
iOS requires explicit user permission for notifications. The app must request the NOTIFICATIONS permission to show alerts, sounds, or badges.
❓ lifecycle
advanced2:00remaining
When is the push token generated and how to handle it?
In expo-notifications, when is the push notification token generated and what is the best practice to handle it in your React Native app?
Attempts:
2 left
💡 Hint
Consider when the app can communicate with the notification service and what steps are needed.
✗ Incorrect
The push token is generated after the app requests and receives notification permissions. Then calling getExpoPushTokenAsync returns the token to send to your backend.
🔧 Debug
advanced2:00remaining
Why does this notification handler not trigger on Android?
Consider this code snippet in a React Native app using expo-notifications:
import * as Notifications from 'expo-notifications';
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
useEffect(() => {
const subscription = Notifications.addNotificationReceivedListener(notification => {
console.log('Notification received:', notification);
});
return () => subscription.remove();
}, []);
Why might the console.log never appear on Android when a notification arrives while the app is foregrounded?
Attempts:
2 left
💡 Hint
Think about how the notification handler affects delivery to listeners.
✗ Incorrect
When shouldShowAlert is true, the notification is shown by the system and not delivered to the listener on Android in the foreground. To receive it in the listener, shouldShowAlert must be false.
expert
2:30remaining
How to navigate to a specific screen when a notification is tapped?
In a React Native app using expo-notifications and React Navigation, how can you navigate to a specific screen when the user taps a push notification that opens the app?
Attempts:
2 left
💡 Hint
Consider which listener specifically handles user interaction with notifications.
✗ Incorrect
addNotificationResponseReceivedListener listens for when the user taps a notification. Inside its callback, you can safely call navigation.navigate to the desired screen.