bluecloud/simple-apns

Laravel package for sending notifications to ios devices via Apple Push Notification Service


License
ISC

Documentation

Simple APNS

Laravel package for sending notifications to ios devices via Apple Push Notification Service

Installation

composer require bluecloud/simple-apns

Publish Config

Next copy the apns.php configuration to your project. Run the following command to publish the vendor config

php artisan vendor:publish --provider="Vendor\Providers\PackageServiceProvider"

Set Environment Variables

Add the following lines to your .env file and set the necessary values. If your key file has password set the APNS_KEY_SECRET to the password

APNS_KEY_ID=SAMPLE_KEY_ID
APNS_TEAM_ID=SAMPLE_TEAM_ID
APNS_APP_BUNDLE_ID=com.example.app
APNS_KEY_SECRET=

Add Key File

Copy your .p8 key file downloaded from apple developer account to the storage/app. Rename it to apns.p8 as indicated below

/storage/app/apns.p8

Usage

Token is a unique user device token generated by the iOS device. This should be captured from device and stored in the database through an API call for instance

$token = "";

$notifier = new APNSNotifier();

$message = new APNSMessage($token);
$message->setTitle("New Message");
$message->setMessage("This is a sample message");
$message->setContent(true);

$notifier->send($message);