Complete the code to import the Expo Notifications module.
import * as [1] from 'expo-notifications';
The correct import is Notifications from expo-notifications. This module handles push notifications in Expo apps.
Complete the code to request push notification permissions.
const { status } = await Notifications.[1]Async();The method to request permissions asynchronously is requestPermissionsAsync. It asks the user to allow notifications.
Fix the error in the code to get the Expo push token.
const tokenData = await Notifications.get[1]Async();The correct method is getExpoPushTokenAsync. It returns the token needed to send push notifications to this device.
Fill both blanks to schedule a notification after 5 seconds.
await Notifications.scheduleNotificationAsync({
content: { body: 'Hello!' },
trigger: { seconds: [1], repeats: [2] }
});The notification should trigger after 5 seconds and not repeat, so seconds: 5 and repeats: false are correct.
Fill all three blanks to add a notification response listener and remove it properly.
const subscription = Notifications.addNotificationResponseReceivedListener(response => {
console.log(response.[1]);
});
// Later to clean up
subscription.[2]();
// To add a notification received listener
const receivedSub = Notifications.addNotificationReceivedListener(notification => {
console.log(notification.[3]);
});The response object has a notification property. To stop listening, call remove() on the subscription. The notification received listener also uses notification.