Hint: Look for async method starting with 'request' [OK]
Common Mistakes:
Using non-existent methods like getPermissions or askForPermissions
Forgetting to await the async call
Using incorrect method names
3. Given the code snippet below, what will be logged when a notification is received?
import * as Notifications from 'expo-notifications';
Notifications.addNotificationReceivedListener(notification => {
console.log(notification.request.content.title);
});
// Assume a notification with title 'Hello User' arrives
medium
A. undefined
B. notification
C. Hello User
D. Error: notification is not defined
Solution
Step 1: Understand the listener callback
The listener receives a notification object, and logs notification.request.content.title.
Step 2: Match the notification content
The notification has a title 'Hello User', so that string will be logged.
Final Answer:
Hello User -> Option C
Quick Check:
Logged title = 'Hello User' [OK]
Hint: Listener logs notification title property [OK]
Common Mistakes:
Expecting the whole notification object to be logged
Confusing property names or missing nested fields
Assuming undefined if not familiar with notification structure
4. What is wrong with this code snippet for getting the push token?
import * as Notifications from 'expo-notifications';
const getToken = async () => {
const token = Notifications.getExpoPushTokenAsync();
console.log(token);
};
getToken();
medium
A. Missing await before Notifications.getExpoPushTokenAsync()
B. Wrong import statement for Notifications
C. console.log should be inside a .then() block
D. getToken function should not be async
Solution
Step 1: Identify async function usage
The method getExpoPushTokenAsync() returns a Promise and must be awaited.
Step 2: Check the code for await
The code calls Notifications.getExpoPushTokenAsync() without await, so token is a Promise, not the actual token.
Final Answer:
Missing await before Notifications.getExpoPushTokenAsync() -> Option A
Quick Check:
Async calls need await to get result [OK]
Hint: Always await async calls to get actual values [OK]
Common Mistakes:
Forgetting to await async functions
Misunderstanding Promises vs values
Incorrect import statements
Logging before Promise resolves
5. You want to send a push notification only when the user has granted permission. Which sequence of steps correctly implements this using expo-notifications?
hard
A. Send notification directly without requesting permission or token
B. Get token first with getExpoPushTokenAsync(), then request permission with requestPermissionsAsync()
C. Only request permission and send notification without getting token
D. Request permission with requestPermissionsAsync(), check status, then get token with getExpoPushTokenAsync() if granted
Solution
Step 1: Request notification permission
Use requestPermissionsAsync() to ask the user for permission and check the returned status.
Step 2: Get push token if permission granted
If permission is granted, call getExpoPushTokenAsync() to get the device token for sending notifications.
Step 3: Send notification using the token
Use the token to send push notifications from your server or app.
Final Answer:
Request permission with requestPermissionsAsync(), check status, then get token with getExpoPushTokenAsync() if granted -> Option D
Quick Check:
Permission first, then token, then send [OK]
Hint: Always request permission before getting token [OK]
Common Mistakes:
Getting token before permission
Sending notifications without token
Skipping permission check
Assuming permission is granted by default
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.