Handle the data payload without user tapping on the notification?

前端 未结 2 1867
日久生厌
日久生厌 2021-01-06 06:14

When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notificatio

2条回答
  •  时光取名叫无心
    2021-01-06 07:00

    If you want to receive data payload when app is not running then you need to use a custom app-server with http protocol(in your case) which will send only data payload no notification and will send data to fcm endpoint like this

        { "data": { "some_key" : "some_value",
     "some_more_key" : "some_more_value" }, 
    "registration_ids": ["device-token","device-token2"] } 
    

    or just to send data from server to one client

    {
       "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
       "data" : {
         "Nick" : "Test",
         "body" : "Your message here",
         "Room" : "Some Test Room"
       },
     }
    

    Then using POST you can send downstream message to your device and it will work the way you want. If you want to have a basic idea of such app server please consider this : How to push notification to client when Firebase has a new entry?

    I have posted basic Java Servlet code here and also a node.js code by firebase official blog.

    Hope it helps.

提交回复
热议问题