Apple Push Notification Service (APNs) notifications channel for Laravel 6 using the new APNs HTTP/2 protocol with token-based (JWT with p8 private key)
smileythane/laravel-apn-notification-channel is a Laravel package for apple push notification service (apns) notifications channel for laravel 6 using the new apns http/2 protocol with token-based (jwt with p8 private key).
It currently has 0 GitHub stars and 10 downloads on Packagist (latest version v1.2.0).
Install it with composer require smileythane/laravel-apn-notification-channel.
Discover more Laravel packages by smileythane
or browse all Laravel packages to compare alternatives.
Last updated
This package makes it easy to send notifications with Laravel 6 to iOS using the new APNs HTTP/2 protocol with token-based (JWT with p8 private key).
Install this package with Composer:
composer require SmileyThane/laravel-apn-notification-channel
If you're installing the package in Laravel 5.4 or lower, you must import the service provider:
// config/app.php
'providers' => [
// ...
SmileyThane\ApnNotificationChannel\ApnServiceProvider::class,
],
Add the credentials to your config/broadcasting.php:
If you are using JWT-based authentication:
// config/broadcasting.php
'connections' => [
...
'apn' => [
'driver' => 'jwt',
'is_production' => env('APP_ENV') === 'production',
'key_id' => env('APN_KEY_ID'), // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/authkey/)
'team_id' => env('APN_TEAM_ID'), // The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/)
'app_bundle_id' => env('APN_APP_BUNDLE_ID'), // The Bundle ID of your application. For example, "com.company.application"
'private_key_path' => env('APN_PRIVATE_KEY', storage_path('apns-private-key.p8')),
'private_key_secret' => env('APN_PRIVATE_KEY_SECRET'),
],
...
],
If you are using Certificate-based authentication:
// config/broadcasting.php
'connections' => [
...
'apn' => [
'driver' => 'certificate',
'is_production' => env('APP_ENV') === 'production',
'app_bundle_id' => env('APN_APP_BUNDLE_ID'), // The Bundle ID of your application. For example, "com.company.application"
'certificate_path' => env('APN_CERTIFICATE_PATH', storage_path('apns-certificate.pem')),
'certificate_secret' => env('APN_CERTIFICATE_SECRET'),
],
...
],
Now you can use the channel in your via() method inside the notification:
use Illuminate\Notifications\Notification;
use SmileyThane\ApnNotificationChannel\ApnMessage;
class AccountApproved extends Notification
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['apn'];
}
/**
* Get the APN representation of the notification.
*
* @param mixed $notifiable
* @return ApnMessage
*/
public function toApn($notifiable)
{
return ApnMessage::create()
->badge(1)
->title('Account approved')
->body("Your {$notifiable->service} account was approved!");
}
}
In your notifiable model, make sure to include a routeNotificationForApn() method, which return one or an array of device tokens.
/**
* Route notifications for the APN channel.
*
* @return string|array
*/
public function routeNotificationForApn()
{
return $this->apn_token;
}
title($str)subtitle($str)body($str)badge($int)sound($str)category($str)launchImage($str)threadId($str)If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.