kingscode / laravel-apns-notification-channel
0.4.1
2020-03-04 10:27 UTC
Requires
- php: ^7.2
- edamov/pushok: ^0.6.4
- illuminate/notifications: ^6.0|^7.0
- illuminate/support: ^6.0|^7.0
README
⚠️ 已废弃 ⚠️
此包是在官方的 Laravel Notification Channels 还不支持“新”APNs API时编写的。
因此,此包不再维护,您应该认真考虑升级到 laravel-notification-channels/apn。
Laravel APNS Notification Channel
苹果推送通知服务(Laravel通知通道)。
安装
需要此包。
composer require kingscode/laravel-apns-notification-channel
在您可以使用此通道之前,您需要从 apple
为您应用程序获取一个 p8
证书。然后在 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), ], ];
使用
在您的 notifiable
模型中,确保包含一个可能返回单个令牌或令牌数组的 routeNotificationForApn()
方法。
public function routeNotificationForApn(): string { return $this->apn_token; }
在您的 Notification
中添加一个返回 Message
的 toApn
方法。
/** * Get the notification in APN format. * * @param $notifiable * @return \KingsCode\LaravelApnsNotificationChannel\Message */ public function toApn($notifiable): Message { return (new Message()) ->setTitle('title') ->setBody('body'); }
并确保您的 via
方法返回 ApnChannel
。
public function via($notifiable): array { return [ApnChannel::class]; }