NativeScript/firebase

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

Woong-znapio opened this issue · 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?

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.

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!

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?

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?

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.

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.