alkurn/yii2-fcm

Yii2 Firebase Cloud Messaging adapter

Installs: 22

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

dev-master 2019-02-14 13:56 UTC

README

This component wraps paragraph1/php-fcm library.

Installation

Preferred way to install is through Composer:

$ composer require alkurn/yii2-fcm:~0.1 --prefer-dist 

Configuration

Add component to your application config:

...
'components' => [
    'fcm' => [
        'class' => 'alkurn\fcm\Fcm',
        'apiKey' => 'your API key', // Server API Key (you can get it here: https://firebase.google.com/docs/server/setup#prerequisites) 
    ],
],
...

Usage

You can find more usage examples here.

$note = Yii::$app->fcm->createNotification("title", "body");
$note->setIcon('icon')
    ->setColor('#ffffff')
    ->setBadge(1);

$message = Yii::$app->fcm->createMessage();
$message->addRecipient(new Device('your-device-token'));
$message->setNotification($note)
    ->setData(['someId' => 111]);

$response = Yii::$app->fcm->send($message);
var_dump($response->getStatusCode());