This package was written at a time where the offical Laravel Notification Channels didn't support the "new" APNs API.
This package is hereby no longer maintained and you should seriously consider upgrading to laravel-notification-channels/apn
Apple push notification service (Laravel notification channel).
Require the package.
composer require kingscode/laravel-apns-notification-channel
You will need to get a p8
certificate for you application from apple
, before you can use this channel. Configure the path in config/broadcasting.php
.
'connections' => [
'apn' => [
'key_id' => env('APN_KEY_ID'),
'team_id' => env('APN_TEAM_ID'),
'app_bundle' => env('APN_APP_BUNDLE'),
'private_key' => storage_path('apn.p8'),
'private_key_password' => env('APN_KEY_PASSWORD', null),
'is_production' => env('APN_PRODUCTION', false),
],
];
In your notifiable
model, make sure to include a routeNotificationForApn()
method which may return a single token or an array of tokens.
public function routeNotificationForApn(): string
{
return $this->apn_token;
}
And in your Notification
add a toApn
method that returns a Message
.
/**
* Get the notification in APN format.
*
* @param $notifiable
* @return \KingsCode\LaravelApnsNotificationChannel\Message
*/
public function toApn($notifiable): Message
{
return (new Message())
->setTitle('title')
->setBody('body');
}
And make sure your via
method returns the ApnChannel
.
public function via($notifiable): array
{
return [ApnChannel::class];
}