understeam/yii2-fcm

Yii2 Firebase Cloud Messaging adapter

Installs: 176 824

Dependents: 4

Suggesters: 0

Security: 0

Stars: 11

Watchers: 3

Forks: 6

Open Issues: 4

Type:yii2-extension

v0.2.0 2016-11-11 13:22 UTC

This package is not auto-updated.

Last update: 2024-10-26 20:21:03 UTC


README

This component wraps paragraph1/php-fcm library.

Installation

Preferred way to install is through Composer:

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

Configuration

Add component to your application config:

...
'components' => [
    'fcm' => [
        'class' => 'understeam\fcm\Client',
        '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("test title", "testing body");
$note->setIcon('notification_icon_resource_name')
    ->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());