Report a bug

We have a push-android notification binding in the response-native for the last 2 weeks, and we also tried with the following to respond to our own module

https://www.npmjs.com/package/react-native-push-notification

Using the above module, we can get a local notification (static application) that works, but the notification from the server is not displayed. we tried " https://github.com/oney/react-native-gcm-android " this also ..

The ability to register with GCM and receive a token from GCM, but using this registered token, cannot receive a notification and

we use php to send notifications from the server, and the php code below

This is the code we use to send notifications from the server,

<?php
function sendPushNotificationToGCM($registatoin_ids, $message) {
    $url = 'https://android.googleapis.com/gcm/send';
    $fields = array('registration_ids' => $registatoin_ids, 'data' => array("title" => 'hi', "message" => $message, ),  );
 define("GOOGLE_API_KEY", "YOUR API KEY");       
  $headers = array(
    'Authorization: key=' . GOOGLE_API_KEY,
    'Content-Type: application/json'
  );
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_POST, true);
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
 $result = curl_exec($ch);             
 if ($result === FALSE) {
    die('Curl failed: ' . curl_error($ch));
 }
 curl_close($ch);
 return $result;
  }
 ?>

How can we overcome this?

+4
4

+1
Try this php code

<?php
    //Generic php function to send GCM push notification
   function sendMessageThroughGCM($registatoin_ids, $message) {
        //Google cloud messaging GCM-API url
        $url = 'https://android.googleapis.com/gcm/send';
        $fields = array(
            'registration_ids' => $registatoin_ids,
            'data' => $message,
        );
        // Update your Google Cloud Messaging API Key
        define("GOOGLE_API_KEY", "Browswer Key");       
        $headers = array(
            'Authorization: key=' . GOOGLE_API_KEY,
            'Content-Type: application/json'
        );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);   
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
        $result = curl_exec($ch);               
        if ($result === FALSE) {
            die('Curl failed: ' . curl_error($ch));
        }
        curl_close($ch);
        return $result;
    }
?>
<?php

    //Post message to GCM when submitted
    $pushStatus = "GCM Status Message will appear here";    
    if(!empty($_GET["push"])) { 
        $gcmRegID  = file_get_contents("GCMRegId.txt");
        $pushMessage = $_POST["message"];   
        if (isset($gcmRegID) && isset($pushMessage)) {      
            $gcmRegIds = array($gcmRegID);
            $message = array("m" => $pushMessage);  
            $pushStatus = sendMessageThroughGCM($gcmRegIds, $message);
        }       
    }

    //Get Reg ID sent from Android App and store it in text file
    if(!empty($_GET["shareRegId"])) {
        $gcmRegID  = $_POST["regId"]; 
        file_put_contents("GCMRegId.txt",$gcmRegID);
        echo "Done!";
        exit;
    }   
?>
+3

push- . , , . .

+2

Php, , , ?

push-, FCM, ?

Cloud Messaging Firebase Firebase. .

1. Firebase Firebase console, . Google, , " Google". " ".

2. Firebase Android- . Google, , .

3. . , ; Firebase.

4. google-services.json. .

5. , , /.

, , "", "".

enter image description here

" " push-.

FCM " ".

If you still do not receive a push notification, check if you have completed all the steps that are provided by the module responsible for the response. Remember to add the google-services.json file to the android / app folder.

This works for me.

IF you receive notifications, then there is some problem with the server code.

0
source

All Articles