Firebase cloud messaging for Yii2
Very simple FCM component for yii2, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Add, (*3)
"matthew-p/yii2-fcm-component": "^1.0"
to the require section of your composer.json
file., (*4)
and, (*5)
{
"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., (*6)
Usage
Once the extension is installed, simply use it in your code by:, (*7)
In config main.php:, (*8)
...
'components' => [
...
'fcm' => [
'class' => \MP\Fcm\FcmComponent::class,
'apiKey' => 'sampleKey',
],
...
],
...
Use:, (*9)
// 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, (*10)
That's all. Check it., (*11)