firebase icon indicating copy to clipboard operation
firebase copied to clipboard

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

Open Woong-znapio opened this issue 11 months ago • 6 comments

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 avatar Jan 11 '25 09:01 Woong-znapio

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.

pazaan avatar Jan 12 '25 00:01 pazaan

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 avatar Jan 16 '25 12:01 Woong-znapio

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?

Woong-znapio avatar Jan 21 '25 07:01 Woong-znapio

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?

pazaan avatar Jan 21 '25 09:01 pazaan

Thanks! I have tried exactly same thing but it didn't work. At the end, I resolve the issue sending twice with different parameters to work.

Woong-znapio avatar Jan 28 '25 09:01 Woong-znapio

I have a similar problem. I specifically do not want to receive notification push, but I only need data push.

In Android, if the application is completely disabled, I was unable to get the date, it simply does not come.

simensBat avatar Feb 21 '25 14:02 simensBat