Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

FCN Notifications trouble #150

Open
ephp opened this issue Nov 10, 2016 · 1 comment
Open

FCN Notifications trouble #150

ephp opened this issue Nov 10, 2016 · 1 comment

Comments

@ephp
Copy link

ephp commented Nov 10, 2016

I've some trouble with FCM notifications.

This is my config.yml

rms_push_notifications:
  android:
      fcm:
          api_key: <my FCM Key> 
          use_multi_curl: true
     ios:
          sandbox: true
          pem: %kernel.root_dir%/var/ios/<myCert>.pem
          passphrase: ~

And this is my test code

    /**
     * @Route("/test", name="test")
     */
    public function testAction(Request $request)
    {
        $notice = json_decode(Curl::curlGet('https://api.chucknorris.io/jokes/random'));
        // Curl::curlGet($url) is a personal library and they work

        $out = [];

        foreach ($this->findAll("AppBundle:Device") as $device) {
            /* @var $device Device */
            switch (strtolower($device->getOs())) {
                case 'ios':
                    $message = new iOSMessage();
                    $message->setMessage($notice->value);
                    $message->setAPSSound('default');
                    $message->setDeviceIdentifier($device->getToken());

                    $out[] = $this->container->get('rms_push_notifications')->send($message);
                    break;

                case 'android':
                    $message = new AndroidMessage();
                    $message->setFCM(true);
                    $message->setMessage($notice->value);
                    $message->setDeviceIdentifier($device->getToken());

                    $out[] = $this->container->get('rms_push_notifications')->send($message);
                    break;
            }
        }

        return new Response($notice->value . ' - [' . implode(' | ', $out) . ']');
    }

If I try to send a notification, the server response is
Every time Chuck Norris watches on Olympic event, he wins a gold medal. - [Android: | iOS: 1]
Debugging the code in AndroidFCMNotification.php I see:

 foreach ($this->responses as $response) {
            $message = json_decode($response->getContent());
  ->        // $message is null !!!
            if ($message === null || $message->success == 0 || $message->failure > 0) {
                if ($message == null) {
                    $this->logger->error($response->getContent());
                } else {
                    foreach ($message->results as $result) {
                        if (isset($result->error)) {
                            $this->logger->error($result->error);
                        }
                    }
                }
                return false;
            }
        }

This is my google-services_json.js and I think it use the correct api_key

{
  "project_info": {
    "project_number": "...",
    "firebase_url": "https://project.firebaseio.com",
    "project_id": "project",
    "storage_bucket": "project.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "...",
        "android_client_info": {
          "package_name": "com.acme.project"
        }
      },
      "oauth_client": [
        {
          "client_id": "...",
          "client_type": 1,
          "android_info": {
            "package_name": "com.acme.project",
            "certificate_hash": "..."
          }
        },
        {
          "client_id": "...",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "..." <- I USE THIS KEY IN MY CONFIG.YML
        }
      ],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "appinvite_service": {
          "status": 2,
          "other_platform_oauth_client": [
            {
              "client_id": "...",
              "client_type": 3
            }
          ]
        },
        "ads_service": {
          "status": 2
        }
      }
    }
  ],
  "configuration_version": "1"
}

I try the code on my MacBookPro and on my web server (based on Debian 7), but the responses are the same.

How can fix my code?

@opedrero
Copy link

You problem is

$message->setFCM(true);

change for

$message->setGCM(true);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants