This package makes it easy to send notifications with Laravel 5.3+ to iOS using the new APNs HTTP/2 protocol with token-based (JWT with p8 private key).
- Features
- Requirements
- Installation
- Usage
- TODO
- Changelog
- Testing
- Security
- Contributing
- Credits
- License
- Uses new Apple APNs HTTP/2 connection
- Supports JWT-based authentication
- Supports new iOS 10 features such as Collapse IDs, Subtitles and Mutable Notifications
- Uses concurrent requests to APNs
- Tested and working in APNs production environment
- Supports Certificate-based authentication
- PHP >= 7.0
- lib-curl >= 7.46.0 (with http/2 support enabled)
- lib-openssl >= 1.0.2e
Install this package with Composer:
composer require semyonchetvertnyh/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' => [
// ...
SemyonChetvertnyh\ApnNotificationChannel\ApnServiceProvider::class,
],
Add the credentials to your config/broadcasting.php
:
// config/broadcasting.php
'connections' => [
...
'apn' => [
'is_production' => env('APP_ENV') === 'production',
'key_id' => env('APN_KEY_ID'),
'team_id' => env('APN_TEAM_ID'),
'app_bundle_id' => env('APN_APP_BUNDLE_ID'),
'private_key_path' => env('APN_PRIVATE_KEY', storage_path('apns-private-key.p8')),
'private_key_secret' => env('APN_PRIVATE_KEY_SECRET'),
],
...
],
Now you can use the channel in your via()
method inside the notification:
use Illuminate\Notifications\Notification;
use SemyonChetvertnyh\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)
custom($key, $value)
setCustom($array)
titleLocKey($str)
titleLocArgs($array)
actionLocKey($str)
setLocKey($str)
setLocArgs($array)
launchImage($str)
contentAvailability($bool)
mutableContent($bool)
threadId($str)
- Fix Travis CI
- Fix Scrutinizer CI Code Coverage
- Add tests
Please see CHANGELOG for more information what has changed recently.
$ composer test
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.