How to implement firebase cloud messaging in server side?

后端 未结 4 1215
执笔经年
执笔经年 2021-02-08 09:19

After migrating to Firebase, i tested sending notification by using the firebase console it works fine, but i need a daily notification on a specific time so instead of using th

相关标签:
4条回答
  • 2021-02-08 09:37

    I added notification object in my json. I found out that in my remoteMessage.getNotification().getBody() it returns null that's why it doesn't receive any notification send by my cron.

    Edit

    Here's my json object

    $message = array(
                'registration_ids' => $registrationIDs,
                'notification' => array(
                                        "title" => $id, 
                                        "body" => $messageText,
                                        "icon" => "name_of_icon" ),
                'data' => array(
                        "message" => $messageText,
                        "id" => $id,
                ),
        );
    
    0 讨论(0)
  • 2021-02-08 09:42

    try use this :)

    Python client for FCM

    0 讨论(0)
  • 2021-02-08 09:51

    Apart from changing the url to following:

    https://fcm.googleapis.com/fcm/send
    

    You also have to change the way you send request data:

     Content-Type:application/json
     Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
    
     {
       "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", // "to" replaces "registration_ids" of gcm in fcm
       "data" : {
       ...
      },
    }
    

    Check out this complete guide.

    0 讨论(0)
  • 2021-02-08 10:01

    I am not able to comment directly in the selected answer. Take in consideration that the json message changes according to what you want/need to receive in the recipient os (android/ios).

    e.g for android to get the notifications when the app is in background you need to add the data json in your request.

    For iOS the data key is not needed, but you must have the notification key along with isContentAvailble flag set to true and priority set to high.

    In the selected answer as valid, you use registration_ids key should be only used when you are sending the notification to more than one device, maybe you should take a look to the topics notifications.

    0 讨论(0)
提交回复
热议问题