albaraam / yii2-gcm-apns
Yii2 组件,作为 "albaraam/php-gcm-apns" 库的包装器,用于处理移动推送通知。
v1.0.0
2015-12-10 13:45 UTC
Requires
- php: >=5.4.0
- albaraam/php-gcm-apns: ~1.0.0@dev
- yiisoft/yii2: >=2.0.4
This package is not auto-updated.
Last update: 2024-09-14 18:20:37 UTC
README
Yii2 组件,作为 "albaraam/php-gcm-apns" 库的包装器,用于处理移动推送通知。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令:
composer require albaraam/yii2-gcm-apns "~1.0.0"
或将其添加到 composer.json 文件的 require
部分:
"albaraam/yii2-gcm-apns": "~1.0.0"
使用方法
在配置文件中添加并配置组件
'components' => [ 'gcmApns' => [ 'class' => 'albaraam\yii2_gcm_apns\GcmApns', 'google_api_key'=>'your_google_api_key', 'environment'=>\albaraam\yii2_gcm_apns\GcmApns::ENVIRONMENT_SANDBOX, 'pem_file'=>'path/to/pem/file' ], ]
在应用中的任何位置访问它,如下所示:
// Message creation through the message builder. $message = Yii::$app()->gcmApns->messageBuilder("Title","Body"); // Common attributes for both ios and android $message ->setTitle("Title") ->setBody("Body") ->setSound("sound.mp3") ->setData(['foo'=>'bar']); // Android specific attributes $message->android ->setTo("ids") ->setIcon("icon") ->setCollapseKey("collapse_key") ->setColor("#333"); // IOS specific attributes $message->ios ->setTo("ids") ->setSound("sound_ios.mp3") // custom sound for ios ->setBadge(3); // Send message Yii::$app->gcmApns->send($message);