Code Monkey home page Code Monkey logo

rmspushnotificationsbundle's Introduction

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
          dry_run: <bool_use_gcm_dry_run>
  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.

Windows Phone - Toast support

The bundle has beta support for Windows Phone, and supports the Toast notification. Use the WindowsphoneMessage message class to send accordingly.

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.

rmspushnotificationsbundle's People

Contributors

aminin avatar antoinemineau avatar christiaan avatar darwinonline avatar davedevelopment avatar emmanuelvella avatar jmig avatar jonathan-edsitech avatar juaruipi avatar mac-cain13 avatar maximgeerinck avatar mente avatar mshulyak avatar phobetor avatar pskt avatar richsage avatar rjmunro avatar rvanlaarhoven avatar stephanecollot avatar tgallice avatar thefox avatar timesplinter avatar verdet23 avatar zhukv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rmspushnotificationsbundle's Issues

Can't push a message

Hello,

I am trying to push a message to an Android device through GCM and I get this error message:
Maximum execution time of 30 seconds exceeded in vendor\kriswallsmith\buzz\lib\Buzz\Client\MultiCurl.php

Call Stack
8 0.9140 8256128 RMS\PushNotificationsBundle\Service\Notifications->send( ) ..\TeetimeController.php:315
9 0.9149 8257864 RMS\PushNotificationsBundle\Service\OS\AndroidGCMNotification->send( ) ..\Notifications.php:37
10 0.9223 8382208 Buzz\Client\MultiCurl->flush( ) ..\AndroidGCMNotification.php:94

I am sending the message from a local apache server. Could someone help me please ?

Update pizza orders list: is this bundle ok to create it?

Hi,

I have to create a website to order pizzas. I have to create also an android app for the owner of the restaurant, so when someone order a pizza, the android app show the new order on the list of the orders.

Is this bundle ready to create this in the part of server?

If yes, what happens when the connection su**s and the device is not connected at the moment of the push?

Emoji

Hello,

Am trying to send a unicode encoded string like :

\ud83d\ude1d\ud83d\ude1d

But the push message does not display any emoji... only the text.

MultiCurl problem

I think that MultiCurl doesn't work.
I am using this Bundle under Windows with php_curl.dll extenstion enabled.

When I run the code to send Android message, I get 25% CPU usage (Apache) and nothing happens - connection is terminated.
When I use Curl instead of MultiCurl I get
SSL certificate problem, verify that the CA cert is OK. Details:\nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
and when I use my own implementation instead of Buzz everything is working ok.

[Question] GCM key is confusing

I'm generated an API key in the console.google.com

In the config documentation it says <string_android_gcm_api_key> so do I need to generate an Android API key or a Server API key?

Apparently it's a Server Key but the doc it's confusing as it says android_gcm_api_key

Couldn't connect to APN server

Hello everyone,

I'm a new user of the bundle and i got an issue, when i try to send my push i got:
request.CRITICAL: Uncaught PHP Exception RuntimeException: "Couldn't connect to APN server. Error no 0: " at .../vendor/richsage/rms-push

I'm sending an iOs Message, my config is:
rms_push_notifications:
ios:
sandbox: true
pem: %ios_pem%

maybe my problem come from my use of setData() ? should I use addCustomData instead ?

Thanks !

Errors checking - getResponses?

Hi there

After sending push messages as follows:

 $message = new iOSMessage();
 $message->setMessage($body);
 $message->setDeviceIdentifier($uuid);
 $this->getContainer()->get('rms_push_notifications')->send($message) 

The message is not received on the test phones although they are registered to receive remote notifications with the following code (in Swift):

let notifications:Bool = UIApplication.sharedApplication().isRegisteredForRemoteNotifications()

When I check if there are any errors in the bundle, as follows:

$this->getContainer()->get('rms_push_notifications')->getResponses("rms_push_notifications.os.ios")

I receive the following response:

Array
(
    [0] => 1
)

Does the 1 indicate boolean true (i.e. success) or something else? I'm not sure I understand how to debug message sending.

Many thanks!

Matt

request timeout when sending iOS push notif

Hi
My API handles request that fire push notifications to iOS. Sometimes these notification arrive, but sometimes the API request timeouts because of sending notifications.

Does anyone have similiar experience?

Error with pem path : Warning: stream_socket_client()

Hi,

I tried to use the bundle but I get an error with the iOS pem file, I put an absolute path to the file but it doesn't seem to work, would it be possible to have a pem path example to put in the config file?

Thanks you,

Here is the error I get when I try to send a push :
[{"message":"Warning: stream_socket_client(): Unable to set private key file `/home/user/MyApplication/src/MyApplication/WebServiceBundle/Certificate/ck.pem' in /home/user/MyApplication/vendor/richsage/rms-push-notifications-bundle/RMS/PushNotificationsBundle/Service/OS/iOSNotification.php line 181","class":"ErrorException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"/home/user/MyApplication/vendor/richsage/rms-push-notifications-bundle/RMS/PushNotificationsBundle/Service/OS/iOSNotification.php","line":181,"args":[]},{"namespace":"Symfony\Component\HttpKernel
...

No way to send push notifications. No problem with a php code apart to send them.

Hi,

this is my code:

rms_push_notifications:
  android:
      gcm:
          api_key: *****************
          use_multi_curl: true
    public function pushAction()
    {
        $message = new AndroidMessage();
        $message->setGCM(true);

        //$message = new iOSMessage();
        $message->setMessage('Oh my! A push notification!');
        $message->setDeviceIdentifier('*********************');

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

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

When I request pushAction() in my localhost the loading spinner on my browser turns around and around...

In my remote host, I get a 500 error but I can not found any error in the apache log or prod symfony log. This is the host: http://185.37.226.104/push

I don't have problems runnning this code that sends a push notification:

function sendNotification( $apiKey, $registrationIdsArray, $messageData )
{
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey);
$data = array(
'data' => $messageData,
'registration_ids' => $registrationIdsArray
);

$ch = curl_init();

curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send" );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($data) );

$response = curl_exec($ch);
curl_close($ch);

return $response;
}

// Message to send
$message = "the test message";
$tickerText = "ticker text message";
$contentTitle = "content title";
$contentText = "content body";

$registrationId = '********';
$apiKey = "***********";

$response = sendNotification(
$apiKey,
array($registrationId),
array('message' => $message, 'tickerText' => $tickerText, 'contentTitle' => $contentTitle, "contentText" => $contentText) );

echo $response;

Any help?

Im on Ubuntu client and server.

Documentation Insufficient

We should add better documentation for this bundle. iOS Feedback is not specified in README docs, or how to handle responses, from both APN and GCM servers.

Send method remains blocked with an AndroidMessage

Hi!

I've got a little issue, when I'm trying to send a notification, the send call remains blocked and never finishes.
I've got the right configuration, I checked this a couple of times. What is going on?

There's any way to monitoring what is happening?
I know I can use xdebug, but I'm refering programmatically.

Remove note in description about Windows support

In description it states "Supports iOS, Android (C2DM, GCM), Blackberry and Windows Mobile", however as can be seen from the source code and issue #5 Windows mobile is not supported.

Could you please remove the note? It's confusing, thx.

Can not get responses from GCM

It is not possible to get responses from GCM using current version.

We inject service like this: $this->container->get('rms_push_notifications')
so we use RMS\PushNotificationsBundle\Service\Notifications and there is no method like getResponses() which is in RMS\PushNotificationsBundle\Service\OS\AndroidGCMNotification.

I tried to use it and every time I received an exception.

I have a "OS type rms_push_notifications.os.android.gcm not supported " error

Hello everybody,

I'm just beginning using RMSPushNotificationBundle and that's what i did:

  • In android.xml i've set the Api_key (i'm using GCM).
  • In my controller:
    $message = new AndroidMessage();
    $message->setMessage('Oh my! A push notification!');
    $message->setDeviceIdentifier('********');
    $message->setGCM(true);
    $this->container->get('rms_push_notifications')->send($message);
    return new Response('Push notification send!');

I have a problem sending AndroidMessage with GCM enabled, it said:
"OS type rms_push_notifications.os.android.gcm not supported"
Do i need to configure something else ?

[Feature] Multiple APNS projects and certificates

For Apple Push (APNS) we have one certificate for one project.
It could be possible to create multiple projects with this bundle?

I don't see the place in code to define more than one path to certificate for APNS.

Unclear on how to register a device to the system.

It is unclear to me how to register my iOS device through a URL to this push notification system. Is this something we have to build and implement ourselves?

If so, in the code there is a parameter called devcieidentifier would this be the current equivalent of an iOS UDID or is this the token received iOS side when a device has registered for push notifications.

-Thanks,
Daniel

How control status sending message?

This bundle have a problems:

  1. Can not send messages from queue. Can create a collection (ArrayObject)?
  2. Not found control status message. Can return status messages after call send()?

php library

Does it exist a the php library version of this bundle to be used without Symfony?

Versionning of the bundle is weird

The bundle has a 2.0.x-dev branch, which is older than the 0.1.* releases. This is weird given that 2.0 is a higher version number. This branch should either be named with something smaller than 0.1 (for instance 0.0.1) or with a non-semver name (so that its version becomes dev-*, which needs to be required explicitly).

It would also be great to add a branch alias for the master branch, so that it can satisfy unbound constraints: https://getcomposer.org/doc/faqs/why-are-unbound-version-constraints-a-bad-idea.md

Support Integration With FOSUserBundle

This bundle should become easily configurable with FOSUserBundle to allow registration of devices to specific users. Then using the Symfony2 one could use a single function to send a push to all of a user's devices.

Use of JSON_FORCE_OBJECT in iOSNotification.php will not work with loc-args

The format of loc-args in iOS message payload is an array. Using JSON_FORCE_OBJECT breaks the payload format by turning loc-args item into an object. This currently happens on lines 262 and 265 of iOSNotification.php
It appears to be the only parameter that has this requirement, everything else is an object.

Can't manage to get IOS push notification working

I think it's missing some documentation about iOS and how to generate the certificate and passphrase. I've followed a neat video that it's explaining how to do ti (for another service, but still the same process): https://www.youtube.com/watch?v=12yjIm0Z8Cw

  1. Generated CSR from keychain
  2. upload the CSR to apple developer and download the generated certificate
  3. Add this certificate to the keychain
  4. Export the certificate (as p.12 format) setting a passphrase
  5. Copy the exported certificate to the app folder (app/certificates for me)

Here is my configuration:

rms_push_notifications:
    android:
        gcm:
            api_key: xxxxxxx
            use_multi_curl: true # default is true
    ios:
        sandbox: true
        pem: "certificates/xxxx-apns-dev-cert.p12" # can be absolute or relative path (from app directory)
        passphrase: "xxxxx"

Now I have a p12 certification and the passphrase I've created. If I try to send a push notification I get the following error:

PHP Warning: stream_socket_client(): Unable to set local cert chain file `/var/www/xxxx/app/certificates/xxxxx-apns-dev-cert.p12'; Check that your cafile/capath settings include details of your certificate and its issuer in /var/www/xxxx/vendor/richsage/rms-push-notifications-bundle/RMS/PushNotificationsBundle/Service/OS/AppleNotification.php on line 196

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out)

Hello,
i am using this for IOS push notifications all working fine on my localhost but when i upload my project on server it giving error of

CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in vendor/richsage/rms-push-notifications-bundle/RMS/PushNotificationsBundle/Service/OS/AppleNotification.php line 196"

in my config:
ios:
sandbox: true
pem: "%kernel.root_dir%/bin/ck.pem"
passphrase: XXX

Update README

Hello,

it could be nice to say that you have to add the use in the Controller :

use RMS\PushNotificationsBundle\Message\iOSMessage;
use RMS\PushNotificationsBundle\Message\AndroidMessage;
use RMS\PushNotificationsBundle\Message\BlackberryMessage;

when you work late, it's easy to miss a such little thing and waste minutes trying to figure why Symfony can't find the class.

Good job on the whole thing :)
Best regards, Pierre.

Specifying Entrust CA certificate

Hello,

I am a new comer on GitHub and I first want to thank you for this wonderful bundle.

I use it to manage notifications with a cordova based app and it works nice for Android and IOS... when I am in sandbox :) In production environment, I have some problems that I don't know how to solve.

I already have generated the SSL certificate and when I test it in a terminal through an openssl command the APNS (in production mode) responds good. But with the bundle, I don't know how to specify the path to the Entrust certificate (Authority that sign the Apple certificate), which must be added to stream context (with PHP function "stream_context_set_option"). Is there a way to specify it directly or a way to get the context which will be used by the notification service ?

Kind regards
Bérenger Germain

[IOS - Recursive call] Method "sendMessages" sends dozens of notifications

Hello,
I'm having trouble using this bundle in a production environment : some of my notifications are sent dozens of time to the same device.
I'm using $this->container->get('rms_push_notifications')->send($message); in a 50 loops foreach. Everything works fine until a notification is detected as failed. Then the method sendMessages() calls itself recursively to resend to resend the failed messages, but it sends again those that succeded as well.
Here is the recursive call I'm talking about : https://github.com/richsage/RMSPushNotificationsBundle/blob/master/Service/OS/AppleNotification.php#L146

Not sure if it is a misuse of the bundle, or an actual bug. Any help would be appreciated :)

Thank you

Uncatchable exception

Hello,
I'm receiving the following exception:

Exception thrown when handling an exception (Symfony\Component\Debug\Exception\FlattenException: Warning: stream_select() [function.stream-select]: You MUST recompile PHP with a larger value of FD_SETSIZE. It is set to 1024, but you have descriptors numbered at least as high as 5375. --enable-fd-setsize=6144 is recommended, but you may want to set it to equal the maximum number of open files supported by your system, in order to avoid seeing this error again at a later date. in /var/www/vhosts/medinaction.com/var/www/vhosts/medinaction.com/symfony_projects/Mia/vendor/richsage/rms-push-notifications-bundle/RMS/PushNotificationsBundle/Service/OS/AppleNotification.php line 163)

ContextErrorException: Warning: stream_select() [function.stream-select]: You MUST recompile PHP with a larger value of FD_SETSIZE.
It is set to 1024, but you have descriptors numbered at least as high as 5375.
--enable-fd-setsize=6144 is recommended, but you may want to set it
to equal the maximum number of open files supported by your system,
in order to avoid seeing this error again at a later date. in /var/www/vhosts/medinaction.com/var/www/vhosts/medinaction.com/symfony_projects/Mia/vendor/richsage/rms-push-notifications-bundle/RMS/PushNotificationsBundle/Service/OS/AppleNotification.php line 163

Also if I got this, the notification is delivered anyway, my hosting type doesn't allow me to change this parameter (I've opened a ticket already regardig this to them and it seems only private server can change this setting, I'm using ServerGrove).

I'm trying to catch this error and go on with my flow...but I cannot catch this exception, I've tried catching FlattenException, ContextErrorException and Exception but I'm always getting this error.

Is is possible to fix it somehow?
Any applicable solution?

Thank you.

How could I send multiple push notifications ?

Hello,

I have a function (sendPushNotifications) in my controller which send multiple push notifications and then return a Response object.

  • My (huge) problem : before returning the Response object, my "sendPushNotifications" function wait until all push notifications are sent.
  • My question : how can I return the Response object AND THEN send all push notifications ?

Kind regards,
Wanty

GCM Android working randomly on production

Hi !
My script sending Android notifications works perfectly on my dev server, and when I'm migrating it to production, it works like 1 times on 20, the other times :

 $this->container->get('rms_push_notifications')->send($push)

is returning false ...

I think it's not related to my GCM or bundle configuration, because it's exactly the same on dev server, and it works perfectly...

CURL is installed and php5-curl too, and I've tried both false and true on 'use_multi_curl' ...

I'm stuck, please help.

OS type rms_push_notifications.os.ios not supported

cant send message:

$message = new Message\iOSMessage();
$message->setMessage('Oh my! A push notification!');
$message->setDeviceIdentifier('test012fasdf482asdfd63f6d7bc6d4293aedd5fb448fe505eb4asdfef8595a7');
$this->container->get('rms_push_notifications')->send($message); // <---- error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.