laszlo-karpati/gcm-bundle

Endroid Google Cloud Messaging Bundle for Symfony

1.2.0 2012-09-06 18:56 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:33:44 UTC


README

endroid提供

Build Status

此扩展包允许您将Endroid Google Cloud Messaging(endroid/Gcm)库用作解耦服务,并通过Symfony框架进行配置。Google Cloud Messaging是一种帮助开发者将数据从服务器发送到Android设备上的Android应用程序的服务。有关提供的服务更多信息,请参阅endroid/Gcm仓库和Google GCM

knpbundles.com

要求

安装

在composer.json中添加

{
    "require": {
        "endroid/gcm-bundle": "dev-master"
    }
}

安装扩展包

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update endroid/gcm-bundle

Composer会将扩展包安装到项目的vendor/endroid目录。

通过内核启用扩展包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Endroid\Bundle\GcmBundle\EndroidGcmBundle(),
    );
}

配置

config.yml

endroid_gcm:
    api_key: "Your API Key (use the Browser key)"

用法

安装和配置后,可以在控制器中直接引用该服务。

<?php
public function gcmSendAction()
{
    $gcm = $this->get('endroid.gcm');

    $registrationIds = array(
        // Registration ID's of devices to target
    );

    $data = array(
        'title' => 'Message title',
        'message' => 'Message body',
    );

    $response = $gcm->send($data, $registrationIds);

    ...
}

许可协议

此扩展包采用MIT许可协议。有关完整的版权和许可信息,请参阅随源代码一起分发的LICENSE文件。