Skip to content

PHP framework for easy interaction with Apple's Push Notification Service. This is a mirror!

License

Notifications You must be signed in to change notification settings

Zandor300/APNSFramework

Repository files navigation

APNSFramework

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 = "";
$authKeyPath = "";
$authKeyId = "";

try {
    $apns = new APNS($teamId, $bundleId, $authKeyPath, $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 (APNSDeviceTokenInactive $e) {
    // Remove device token from database since it's inactive.
} catch (APNSException $e) {
    echo "Error: " . $e->getMessage();
    // Handle exception
}

Troubleshooting

Certificate errors

You might need to set the root certificate for the APNS request using setRootCertificatePath on the APNS object. You can download this certificate using the link in the Apple Developer documentation: Establish a Trusted Connection to APNs > AAA Certificate Services root certificate

$apns->setRootCertificatePath(__DIR__ . "/AAACertificateServices.crt");

About

PHP framework for easy interaction with Apple's Push Notification Service. This is a mirror!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages