Please provide the following:
- SDK Version: 38
- Platforms(Android/iOS/web/all): Android/iOS
I am looking at the push notification docs and I am using the code to register a handler when the user clicks on a push notification. We have some push notifications that we want to open a URL, so I handle this in the app with:
const useNotificationResponseReceived = () => {
useEffect(() => {
const handler = Notifications.addNotificationResponseReceivedListener(
async ({ notification }) => {
try {
const { data } = notification.request.content
const url = `${data.click_action}`
// if url is a link and is not a deep link to the app from the website
if (
url.startsWith("https://") &&
!url.includes("mywebsite.com")
) {
await Linking.openURL(url)
}
} catch {}
}
)
return () => Notifications.removeNotificationSubscription(handler)
}, [])
}
This works great when the app is open in the background. Although if I close the app, and trigger a push notification, then the handler above doesn’t fire. How can I get the app to handle the push notification in this scenario?