React Native Push Notification for Android

Viewed 6410

We have stuckup with android push notification in react-native for past 2 weeks and also we have tried with following react native module

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

With above module, we are able to get local notification ( static from app ), that is working but notification from server is not displaying. we have tried " https://github.com/oney/react-native-gcm-android " this also ..

Able to register with GCM and get token from GCM but using that registered token ,Cannot get Notification and

we are using php to send notification from server and the php code is below

This is the code we are using to send notification from 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 Answers
Related