richsage / RMSPushNotificationsBundle

NOT MAINTAINED! ⛔️ Push notifications/messages for mobile devices. Supports iOS, Android (C2DM, GCM), Blackberry and Windows Mobile (toast only). A Symfony2 bundle.
MIT License
321 stars 152 forks source link

No way to send push notifications. No problem with a php code apart to send them. #64

Closed Ziiweb closed 10 years ago

Ziiweb commented 10 years ago

Hi,

this is my code:

rms_push_notifications:
  android:
      gcm:
          api_key: *****************
          use_multi_curl: true
    public function pushAction()
    {
        $message = new AndroidMessage();
        $message->setGCM(true);

        //$message = new iOSMessage();
        $message->setMessage('Oh my! A push notification!');
        $message->setDeviceIdentifier('*********************');

        $this->container->get('rms_push_notifications')->send($message);

        return new Response('Push notification send!');
    }

When I request pushAction() in my localhost the loading spinner on my browser turns around and around...

In my remote host, I get a 500 error but I can not found any error in the apache log or prod symfony log. This is the host: http://185.37.226.104/push

I don't have problems runnning this code that sends a push notification:

function sendNotification( $apiKey, $registrationIdsArray, $messageData )
{
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey);
$data = array(
'data' => $messageData,
'registration_ids' => $registrationIdsArray
);

$ch = curl_init();

curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send" );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($data) );

$response = curl_exec($ch);
curl_close($ch);

return $response;
}

// Message to send
$message = "the test message";
$tickerText = "ticker text message";
$contentTitle = "content title";
$contentText = "content body";

$registrationId = '********';
$apiKey = "***********";

$response = sendNotification(
$apiKey,
array($registrationId),
array('message' => $message, 'tickerText' => $tickerText, 'contentTitle' => $contentTitle, "contentText" => $contentText) );

echo $response;

Any help?

Im on Ubuntu client and server.

richsage commented 10 years ago

Your working code doesn't use MultiCurl - try adjusting your GCM configuration to:

use_multi_curl: false

and see if that makes a difference?

Ziiweb commented 10 years ago

Thanks! now is working