Download the PHP package ricwein/push-notifications without Composer
On this page you can find all versions of the php package ricwein/push-notifications. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ricwein/push-notifications
More information about ricwein/push-notifications
Files in ricwein/push-notifications
Package push-notifications
Short Description Push Notifications for iOS (APNS), Android (FCM)
License MIT
Informations about the package push-notifications
PushNotification
... is a small php-library to wrap Apple (APNS) and Google (FCM) Push-Notifications into a simple syntax.
Examples:
Android
iOS
NOTE: The
APNS
Handler uses the new apple push servers, which require HTTP2. Therefore, curl with HTTP2 support must be installed.
mixed
Sending messages to multiple devices of difference operating systems is also simple:
single message / single handler
For single handler messages it's possible to inline the handler into the device-destination array. The handler is then freed automatically after the message was send.
usage
This class uses the root-namespace ricwein\PushNotification
.
init
The libraries main class is called PushNotification
and requires an array of available push-handlers for the constructor. It's possible to set an ID as the handlers array key, to allow assigning devices to the handler later on.
Available push-handler are:
- Apple:
PushNotification\Handler\APNS
- Google:
PushNotification\Handler\FCM
They're all extending PushNotification\Handler
configuration
Since all push-settings are push-handler specific, the settings are directly applied in the handler constructors.
-
APNS:
- FCM:
It's also possible to have multiple push-handlers with different configurations like:
sending
Sending is either available for a message object or a raw payload.
- A message object is translated into a native push-notification message with body and title for FCM or APNS before sending.
- A raw payload (array) is sent 'as it is' which might not be a good idea, if you want to mix APNS and FCM in one request.
error handling
The PushNotification::send()
method returns an Result
object. This usually contains an array of per device errors. If everything succeeded, the entry is null. You can fetch failed device-messages with:
Errors are handled as Exceptions, so it's possible to just throw them. To simply just throw the first error if one occurred, call:
Be aware: Sometimes other failures than usage-errors occur. APNS and FCM can respond with explicit reasons, which will be handled as ResponseReasonException
. It's a good idea to not just throw them (away), but handle them other ways. E.g. you might want to delete or update device-tokens which were marked as invalid.
All versions of push-notifications with dependencies
ext-json Version *
ext-curl Version *
ext-bcmath Version *
edamov/pushok Version ^0.15.0