Firebase Notification not received on device when sent via cURL/PHP

后端 未结 4 958
故里飘歌
故里飘歌 2021-01-02 10:16

I have an iOS app which is live on the app store. I am able to send push notifications to iOS devices which have the app installed, but only when I send them from the Fireba

4条回答
  •  醉话见心
    2021-01-02 10:40

    There were two issues:

    1. I needed to include a notification section in the payload instead of data
    2. Somehow the payload wasn't being formatted properly by PHP.

    In the end I used the PHP function shell_exec() to do a cURL request over SSH instead. This isn't ideal but it got the job done.

    Example code:

    shell_exec('curl -X POST --header "Authorization: key=" --header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"'.$to.'\",\"priority\":\"high\",\"notification\":{\"body\": \"'.stripslashes($message).'\"}}"');
    

提交回复
热议问题