When a Firebase Cloud Messaging (FCM) notification is received while the app is in the foreground, what is the default behavior?
Think about how apps behave when they are open and receiving messages.
When the app is in the foreground, FCM does not automatically show notifications. The app receives the message and must decide how to display it.
Which code snippet correctly sets up a Firebase messaging handler to receive messages when the app is in the foreground (using JavaScript)?
import { getMessaging, onMessage } from 'firebase/messaging'; const messaging = getMessaging(); onMessage(messaging, (payload) => { console.log('Message received:', payload); // Display notification here });
Check the official Firebase Web SDK method for foreground message handling.
The onMessage function from firebase/messaging is the correct way to listen for foreground messages.
You want to ensure users see important notifications even when your app is open. Which architecture best supports this?
Consider how to control notification display when the app is active.
Data messages allow the app to receive payloads and decide how to display notifications, ensuring visibility in foreground.
What is a key security best practice when handling FCM messages in the foreground?
Think about how untrusted data can affect your app UI.
Even though messages come from Firebase, they can contain user-generated content. Always validate and sanitize to avoid security issues.
Which statement correctly describes the difference in foreground notification handling between Android and iOS when using Firebase Cloud Messaging?
Consider platform differences in notification systems.
Both Android and iOS do not display notifications automatically when the app is in foreground; the app must handle it manually.