Skip to content

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

Description

@Woong-znapio

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?

Activity

  1. 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?[/+] on Jan 11, 2025
  2. pazaan commented on Jan 12, 2025

    @pazaan

    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.

  3. Woong-znapio commented on Jan 16, 2025

    @Woong-znapio
    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!

  4. Woong-znapio commented on Jan 21, 2025

    @Woong-znapio
    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?

  5. pazaan commented on Jan 21, 2025

    @pazaan

    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?

  6. Woong-znapio commented on Jan 28, 2025

    @Woong-znapio
    Author

    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.

  7. simensBat commented on Feb 21, 2025

    @simensBat

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions