Developed with love by KnpLabs Hire us for your project!
200

RMSPushNotificationsBundle

by richsage

Push notifications/messages for mobile devices. Supports iOS, Android (C2DM, GCM), Blackberry and Windows Mobile (toast only). A Symfony2 bundle.

RMSPushNotificationsBundle

A bundle to allow sending of push notifications to mobile devices. Currently supports Android (C2DM, GCM), Blackberry and iOS devices.

Installation

To use this bundle in your Symfony2 project add the following to your composer.json:

{
    "require": {
        // ...
        "richsage/rms-push-notifications-bundle": "dev-master"
    }
}

and enable it in your kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new RMS\PushNotificationsBundle\RMSPushNotificationsBundle(),
    );
}

NOTE: If you are still using Symfony 2.0, please use the symfony2.0 branch.

Configuration

Configuration options available are as follows. Note that the specific services will
only be available if you provide configuration respectively for them.

rms_push_notifications:
  android:
      timeout: 5 # Seconds to wait for connection timeout, default is 5
      c2dm:
          username: <string_android_c2dm_username>
          password: <string_android_c2dm_password>
          source: <string_android_c2dm_source>
      gcm:
          api_key: <string_android_gcm_api_key> # This is titled "Server Key" when creating it
          use_multi_curl: <boolean_android_gcm_use_multi_curl> # default is true
  ios:
      timeout: 60 # Seconds to wait for connection timeout, default is 60
      sandbox: <bool_use_apns_sandbox>
      pem: <path_apns_certificate> # can be absolute or relative path (from app directory)
      passphrase: <string_apns_certificate_passphrase>
  mac:
      timeout: 60 # Seconds to wait for connection timeout, default is 60
      sandbox: <bool_use_apns_sandbox>
      pem: <path_apns_certificate>
      passphrase: <string_apns_certificate_passphrase>
  blackberry:
      timeout: 5 # Seconds to wait for connection timeout, default is 5
      evaluation: <bool_bb_evaluation_mode>
      app_id: <string_bb_app_id>
      password: <string_bb_password>
  windowsphone:
      timeout: 5 # Seconds to wait for connection timeout, default is 5

NOTE: If you are using Windows, you may need to set the Android GCM use_multi_curl flag to false for GCM messages to be sent correctly.

Timeout defaults are the defaults from prior to the introduction of this configuration value.

Usage

A little example of how to push your first message to an iOS device, we'll assume that you've set up the configuration correctly:

use RMS\PushNotificationsBundle\Message\iOSMessage;

class PushDemoController extends Controller
{
    public function pushAction()
    {
        $message = new iOSMessage();
        $message->setMessage('Oh my! A push notification!');
        $message->setDeviceIdentifier('test012fasdf482asdfd63f6d7bc6d4293aedd5fb448fe505eb4asdfef8595a7');

        $this->container->get('rms_push_notifications')->send($message);

        return new Response('Push notification send!');
    }
}

The send method will detect the type of message so if you'll pass it an AndroidMessage it will automatically send it through the C2DM/GCM servers, and likewise for Mac and Blackberry.

Android messages

Since both C2DM and GCM are still available, the AndroidMessage class has a small flag on it to toggle which service to send it to. Use as follows:

use RMS\PushNotificationsBundle\Message\AndroidMessage;

$message = new AndroidMessage();
$message->setGCM(true);

to send as a GCM message rather than C2DM.

iOS Feedback service

The Apple Push Notification service also exposes a Feedback service where you can get information about failed push notifications - see here for further details.

This service is available within the bundle. The following code demonstrates how you can retrieve data from the service:

$feedbackService = $container->get("rms_push_notifications.ios.feedback");
$uuids = $feedbackService->getDeviceUUIDs();

Here, $uuids contains an array of Feedback objects, with timestamp, token length and the device UUID all populated.

Apple recommend you poll this service daily.

Thanks

Firstly, thanks to all contributors to this bundle!

Secondly, thanks to JetBrains for their sponsorship of an open-source PhpStorm licence for this project.

Copyright (c) 2012-2015 Rich Sage

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rms_push_notifications:
android:
timeout: 5
username:
password:
source:
c2dm:
username: ~ # Required
password: ~ # Required
source:
gcm:
api_key: ~ # Required
use_multi_curl: true
ios:
timeout: 60
sandbox: false
pem: ~ # Required
passphrase:

# PHP >= 5.4.0 and each messaged must be UTF-8 encoding
json_unescaped_unicode: false
mac:
timeout: 60
sandbox: false
pem: ~ # Required
passphrase:

# PHP >= 5.4.0 and each messaged must be UTF-8 encoding
json_unescaped_unicode: false
blackberry:
timeout: 5
evaluation: false
app_id: ~ # Required
password: ~ # Required
windowsphone:
timeout: 5
  • Merge pull request #90 from andrewbrereton/master
    By richsage, 2 years ago
  • Merge pull request #84 from richsage/configure-timeout
    By richsage, 2 years ago
  • Merge pull request #92 from c4d3r/master
    By richsage, 2 years ago
  • Ability to add all identifiers at once
    By c4d3r, 2 years ago
  • Clutching at straws.
    By , 2 years ago
  • Get length of json paload, not the push token
    By andrewbrereton, 2 years ago
  • Add ability for to send MDM push notifications to Apple devices.
    By andrewbrereton, 2 years ago
  • Merge pull request #85 from aqnouch/master
    By richsage, 2 years ago
  • Updated copyright to 2015
    By aqnouch mohammed, 2 years ago
  • Add timeout param to DI extension, update tests.
    By richsage, 2 years ago
  • Fix tests.
    By richsage, 2 years ago
  • Update README.
    By richsage, 2 years ago
  • Add timeout to iOS and Mac.
    By richsage, 2 years ago
  • Add timeout to Windows Phone.
    By richsage, 2 years ago
  • Add timeout to Blackberry.
    By richsage, 2 years ago
  • Add timeout configuration for Android.
    By richsage, 2 years ago
  • Bump Travis to use higher PHP versions.
    By richsage, 2 years ago
  • Add Thanks section.
    By richsage, 2 years ago
  • Add explanatory note about GCM Server Key (fixes #61)
    By richsage, 2 years ago
  • Remove GCM key length restriction in test command (fixes #79)
    By richsage, 2 years ago
  • Add branch alias for unbound constraints (#77).
    By richsage, 2 years ago
  • Add note about Symfony2.0
    By richsage, 2 years ago
  • Merge pull request #74 from EmmanuelVella/patch-2
    By richsage, 2 years ago
  • Add supports method
    By emmanuelvella, 2 years ago
  • Merge pull request #72 from mshulyak/master
    By richsage, 2 years ago
  • Updated iOS Service for sending log-arcs without JSON_FORCE_OBJECT
    By , 2 years ago
  • Merge pull request #71 from pskt/windows-phone
    By richsage, 2 years ago
  • Fixed tests for Windowsphone
    By , 2 years ago
  • Fixes in windows phone support
    By pskt, 2 years ago
  • Initial support for Windows Phone
    By pskt, 2 years ago