Apple APN Push Notification Channel
1,131,548
177
9
Package Data
Maintainer Username: dwightwatson
Maintainer Contact: info@fruitcake.nl (Fruitcake)
Package Create Date: 2016-08-24
Package Last Update: 2024-03-01
Home Page: http://laravel-notification-channels.com
Language: PHP
License: MIT
Last Refreshed: 2024-04-23 03:03:00
Package Statistics
Total Downloads: 1,131,548
Monthly Downloads: 19,195
Daily Downloads: 815
Total Stars: 177
Total Watchers: 9
Total Forks: 53
Total Open Issues: 2

Laravel APN (Apple Push) Notification Channel

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

This package makes it easy to send notifications using Apple Push (APN) with Laravel 5.8.

Contents

Installation

Install this package with Composer:

composer require laravel-notification-channels/apn

Setting up the APN service

Before using the APN Service, follow the Provisioning and Development guide from Apple

You will need to generate a certificate for you application, before you can use this channel. Configure the path in config/broadcasting.php

    'connections' => [
      ....
      'apn' => [
          'environment' => ApnChannel::PRODUCTION, // Or ApnChannel::SANDBOX
          'certificate' => '/path/to/certificate', 
          'pass_phrase' => null, // Optional passPhrase
      ],
      ...
    ]

Usage

You can now send messages to APN by creating a ApnMessage:

use NotificationChannels\Apn\ApnChannel;
use NotificationChannels\Apn\ApnMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [ApnChannel::class];
    }

    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 tokens.

public function routeNotificationForApn()
{
    return $this->apn_token;
}

Available methods

  • title($str)
  • body($str)
  • badge($integer)
  • custom($customData)

Feedback Service

Apple implements a Feedback Service. See the Zend APN documentation

APNS has a feedback service that you must listen to. Apple states that they monitor providers to ensure that they are listening to this service.

The feedback service simply returns an array of Feedback responses. All tokens provided in the feedback should not be sent to again; unless the device re-registers for push notification. You can use the time in the Feedback response to ensure that the device has not re-registered for push notifications since the last send.

Example using the ApnChannel:

use App\User;
use NotificationChannels\Apn\FeedbackService;
use NotificationChannels\Apn\ApnFeedback;

$feedbackService = app(FeedbackService::class);

/** @var ApnFeedback $feedback */
foreach ($feedbackService->get() as $feedback) {
    User::where('apn_token', $feedback->token)
        ->update(['apn_token' => null]);
}

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email info@fruitcake.nl instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.