Download the PHP package potagercity/expo-notifications-bundle without Composer
On this page you can find all versions of the php package potagercity/expo-notifications-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download potagercity/expo-notifications-bundle
More information about potagercity/expo-notifications-bundle
Files in potagercity/expo-notifications-bundle
Package expo-notifications-bundle
Short Description Bundle to handle the BE tasks of the push notifications service for the expo react-native Framework.
License MIT
Homepage http://solvecrew.github.com
Informations about the package expo-notifications-bundle
README
This Bundles purpose is to handle the BE tasks of the push notifications service for the expo react-native Framework.
Installation
Install the bundle using composer:
Enable the Bundle in the app/AppKernel.php file:
Configuration
At the moment, this bundle only has a single optional configuration parameter.
If you want (optional), add this to your app/config/config.yml
file:
And then add the expo_api_endpoint
parameter in your app/config/parameters.yml
file:
If you prefer to not add it as a parameter in your parameters.yml
file you can add the URI in your config.yml file directly:
IMPORTANT: All this is completely OPTIONAL. If you don't add the config at all, it will use https://exp.host/--/api/v2/push/send
as fallback since it is the endpoint from the official Expo Documentation.
Usage
This bundle provides you with an easy way to send push notifications for a front-end application using the Expo React-Native framework. Therefore the bundle provides you with several helpful things:
- NotificationContentModel: A model representing the requestdata for a single notification. As specified by the Expo API.
- NotificationManager: A Manager to handle the preparing of the notification, the sending and the reponse.
The service of the NotificationManager is sc_expo_notifications.notification_manager
.
- Use it in a controller with
$this->container->get('sc_expo_notifications.notification_manager')
. - Inject it as a dependency like:
NOTE that the important part here is the arguments: ['@sc_expo_notifications.notification_manager']
of course.
After you have the NotificationManager available you can access its functions. Popular functions are:
- sendNotifications(...): Send multiple notifications in one API request.
Therefore you need to provide an array of messages
as strings and an array of tokens
as strings (to be more
specific: The recipients ExponentPushToken. Like sITGtlHf1-mSgUyQIVbVMJ
, without the ExponentPushToken[]
sourrounding.). The first message in the messages array will be delivered to the first token (recipient) in the tokens
array. And so on. Optionally you can provide a titles
array which holds titles for the notifications. Last, you can
provide an array of data arrays that will be added to the notification as a JSON object for further handling in the
front-end. It is important to know, that each notification needs an array as data! See the Full Example below for more
information.
The function returns you an array of NotificationContentModel. One for each notification that was tried to send. Those NotificationContentModels hold all the information about the notification.
For example:
- to: The token that represents the recipient.
- title: The title, if provided.
- body: The actual message of the notification.
- wasSuccessful: A boolean indicating whether the notification was send (does NOT mean it was recieved or viewed).
- responseMessage: A message that was returned by the Expo API on unsuccessful request for the specific notification.
- responseDetails: An array holding error specific information.
- sendNotification(...): Send a single notification providing only a message string and a token. Optionally a title.
As you can see, this one is really straight forward. It returns a single NotificationContentModel as descibed above. The title (string) and the data (array) are optional. If provided, $data must be an array.
Full Example
To even ease the integration process further, see the following example.
If your use case is more complex or you just want to leverage more of the notification funtions you can use the
sendNotificationHttp
function of the NotificationManager. For that you need to create the NotificationContentModel
yourself.
If you want to send multiple notifications this way, use sendNotificationsHttp
(plural).
Troubleshooting
If the service sc_expo_notifications.notification_manager
is not available for some reason, debug your container with
bin/console debug:container | grep notification
.
You should see:
The first service is the guzzle client which is the dependency of our bundle. The second service is the notificationManager the bundle provides to handle all notification related tasks.
Based on the Expo push notifications API
To see the process and the API documentation for the Expo push notifications service see: https://docs.expo.io/versions/v14.0.0/guides/push-notifications.html
LICENSE
Created by SolveCrew 2017. Contact us if you like: [email protected] or visit our website: www.solvecrew.com MIT
All versions of expo-notifications-bundle with dependencies
eightpoints/guzzle-bundle Version ^6.0|~7.0
guzzlehttp/guzzle Version ~6.0
eightpoints/guzzle-wsse-middleware Version ~4.0
symfony/dependency-injection Version ~2.3|~3.0|~4.0
symfony/expression-language Version ~2.3|~3.0|~4.0
symfony/event-dispatcher Version ~2.3|~3.0|~4.0
symfony/http-kernel Version ~2.3|~3.0|~4.0
psr/log Version ~1.0