Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@nativescript/firebase-messaging] How to catch the push notification message on background without tapping the notification? #277

Open
Woong-znapio opened this issue Jan 11, 2025 · 4 comments

Comments

@Woong-znapio
Copy link

Hi, I am using push notification to sync some data.

On foreground, it automatically trigger .onMessage()
On background, user need to click the notification then trigger .onMessageTap()

What I want to do is even if user ignore the notification, catch the message and sync some data on background.
Is there any way to address this?

@Woong-znapio Woong-znapio changed the title [@nativescript/firebase-messaging] Can I intercept the push notification before displaying it to screen? [@nativescript/firebase-messaging] How to catch the push notification message on background without tapping the notification? Jan 11, 2025
@pazaan
Copy link

pazaan commented Jan 12, 2025

You need to send a background notification for this to trigger.
Note that you need to set the correct apns-push-type and apns-priority headers for this to work.
You can generate these in the CloudKit Notifications dashboard, or with the following cURL command:

curl -v \
  --header "authorization: bearer ${AUTHENTICATION_TOKEN}" \
  --header "apns-topic: ${APP_BUNDLE_ID}" \
  --header "apns-push-type: background" \
  --header "apns-priority: 5" \
  --header "apns-expiration: 0" \
  --data '{"aps":{"content-available":1},"key1":"hello!","key2":"second bit of custom data"}' \
  --http2  "https://api.development.push.apple.com:443/3/device/${DEVICE_TOKEN}"

If you're using other software on the server side, it also needs to support background pushes.

Unfortunately I haven't yet been able to figure out a way to get this to work in the iOS Simulator.

@Woong-znapio
Copy link
Author

Thanks a lot! I am having another issue that nativescript is not detecting my physical device but Xcode does. I will test with your code with physical device soon once I figure out!

@Woong-znapio
Copy link
Author

Hi, thanks for the info and it worked as expected on ios. But on Android, still not trigger any of .onMessage() or .onMessageTap() when app is on background or killed. Any idea?

@pazaan
Copy link

pazaan commented Jan 21, 2025

I haven't tried it on Android, so I can't help with that, sorry. But I expect there's a specific way that you have to send the message (like in iOS). Have you tried working through something like this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants