zandor300/apnsframework

PHP framework for easy interaction with Apple's Push Notification Service.

1.1.0 2019-12-28 18:01 UTC

This package is auto-updated.

Last update: 2020-05-28 18:57:39 UTC


README

Build Version License PHP Version Downloads

PHP framework for easy interaction with the Apple Push Notification Service.

Install

You can use composer to include this framework into your project. The project is available through Packagist.

composer require zandor300/apnsframework

Dependencies

This framework depends on the firebase/php-jwt package.

Usage

Creating APNS object.

use APNSFramework;

$teamId = "";
$bundleId = "";
$authKeyUrl = "";
$authKeyId = "";

try {
    $apns = new APNS($teamId, $bundleId, $authKeyUrl, $authKeyId);
} catch (APNSException $e) {
    echo "Error: " . $e->getMessage();
    // Handle exception
}

Creating a basic notification

$notification = new APNSNotification();

$notification->setTitle("Example Notification");
$notification->setBody("This is an example notification!");

$notification->setBadge(2);

Creating a token object

try {
    $tokenString = "<FILL IN THE APNS TOKEN>";

    $environment = APNSTokenEnvironment::development;
    //$environment = APNSTokenEnvironment::production;

    $token = new APNSToken($tokenString, $environment);
} catch (APNSException $e) {
    echo "Error: " . $e->getMessage();
    // Handle exception
}

Sending the notification

try {
    $apns->sendNotification($notification, $token);
} catch (APNSException $e) {
    echo "Error: " . $e->getMessage();
    // Handle exception
}