Listen and Respond to Notifications
Last updated
Handle notifications when they are received while the app is running or when the user taps a notification to open the app.
NotificationServicesOnNotificationReceived
Listen for notification events
NotificationServicesGetReceivedNotificationInfo
Extract notification details
notificationId (String)
notificationTitle (String)
notificationBody (String)
wasLaunchedFromNotification (Bool)
userInfoKeys/userInfoValues (String arrays, optional)
Action: NotificationServicesOnNotificationReceived
Outputs:
notificationId → notificationId variable
title → notificationTitle
body → notificationBody
wasLaunchedFromNotification → wasLaunchedFromNotification
Events:
receivedEvent → HandleNotification
Note: This is a persistent listener state - it remains active and fires the event each time a notification is received.
Logic: Check wasLaunchedFromNotification
If true: User tapped notification → Navigate to relevant content
If false: Notification received in foreground → Show in-app banner
Optional: Extract payload Use NotificationServicesGetReceivedNotificationInfo to read userInfoKeys / userInfoValues (and other fields like subtitle/badge/sound).
Based on extracted payload (for example, contentId), navigate to the appropriate scene or UI element.
The listener continues to monitor for new notifications.
Listener Not Firing: Ensure the state with OnNotificationReceived is active when notification arrives
Multiple Triggers: Each notification fires the event once; handle event properly to avoid duplicate actions
Background vs Foreground: wasLaunchedFromNotification distinguishes between tapped (true) and foreground (false)
UserInfo Parsing: Ensure JSON format is valid when building notifications
Foreground Notification:
App is open → Notification arrives → Show in-app toast/banner
Background/Closed Tap:
App closed → User taps notification → App launches → Navigate directly to content
Keep the HandleNotification state logic simple and fast. Heavy operations should be deferred to avoid blocking the notification callback.
Last updated
State: ListenForNotifications (PERSISTENT)
└─ Stays active, fires receivedEvent on each notification
OnEnter: Subscribe to notification events
OnExit: Unsubscribe from events