matthew-p / yii2-fcm-component
Very simple fcm component for yii2
Installs: 888
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 2
Open Issues: 0
Type:yii2-extension
Requires
- understeam/yii2-fcm: ^0.2.1
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-12-19 22:22:21 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.