matthew-p/yii2-fcm-component

Very simple fcm component for yii2

1.3 2020-02-19 11:37 UTC

This package is auto-updated.

Last update: 2024-04-19 20:50:15 UTC


README

Very simple FCM component for yii2

Installation

The preferred way to install this extension is through composer.

Add

"matthew-p/yii2-fcm-component": "^1.0"

to the require section of your composer.json file.

and

{
  "type": "git",
  "url": "https://github.com/MatthewPattell/yii2-fcm"
},
{
  "type": "git",
  "url": "https://github.com/MatthewPattell/php-fcm"
}

to the repositories section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by:

In config main.php:

...
'components' => [
    ...
    'fcm' => [
        'class'  => \MP\Fcm\FcmComponent::class,
        'apiKey' => 'sampleKey',
    ],
    ...
],
...

Use:

// Send to topic
$message = [
    'topic' => 'sampleChannelID',
    'data'  => [
        'sample1' => 'test'
    ],
];

$notification = ['key' => 'samplePushMessageKey'];


Yii::$app->fcm->pushTopic($message, $notification);

// Send to device
$message = [
    'device' => 'sampleDeviceToken',
    'data'   => [
        'sample1' => 'test'
    ],
];
Yii::$app->fcm->pushDevice($message, $notification);

See $notification configuration in \MP\Fcm\FcmComponent::NOTIFICATION_DEFAULT

That's all. Check it.