andymswick / expo
Laravel 用于 Expo 推送通知的驱动程序。
Requires
- php: >=7.2
- guzzlehttp/guzzle: ^6.3
- illuminate/notifications: ~5.5 || ~6.0
- illuminate/support: ~5.5 || ~6.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-09-04 05:46:04 UTC
README
此包使得使用 Laravel 5.5+ 和 6.0 向您的 Expo 应用发送推送通知变得简单。
有关如何在您的 Expo 应用内部设置推送通知的更多信息,请参阅他们的 推送通知文档。
内容
安装
您可以使用以下命令通过 composer 安装此包
composer require "laravel-notification-channels/expo"
包将自动注册自身。
您可以使用以下命令发布可选迁移
php artisan vendor:publish --provider="NotificationChannels\Expo\ExpoServiceProvider" --tag="migrations"
迁移发布后,您可以通过运行迁移来向用户表添加 push_token
php artisan migrate
您可以使用以下命令发布可选的配置文件
php artisan vendor:publish --provider="NotificationChannels\Expo\ExpoServiceProvider" --tag="config"
这是已发布配置文件的内容
return [ /* * The attribute on the notifiable that will be accessed by default for the `to` method. */ 'token' => env('EXPO_PUSH_TOKEN', 'push_token'), ];
用法
如果通知支持作为 Expo 推送通知发送,您应在通知类上定义一个 toExpo
方法。此方法将接收一个 $notifiable
实体并应返回一个 NotificationChannels\Expo\ExpoMessage
实例。Expo 消息可以包含标题、正文以及 "jsonData",它将发送到 Expo 应用额外的数据。让我们看一个基本的 toExpo
示例
// ... use NotificationChannels\Expo\ExpoChannel; use NotificationChannels\Expo\ExpoMessage; class CheckInTime extends Notification { // ... public function via($notifiable) { return [ExpoChannel::class]; } public function toExpo($notifiable) { return (new ExpoMessage) ->title("It's time to check in!") ->body('Check in now for us to print your name badge') ->setJsonData(['screen' => 'CheckIn']); } }
如果通知者没有在 config/expo.php
中设置 token
值,则必须使用 to
方法。您可以选择发布此配置以及一个迁移,该迁移将在 remember_token
后向 users
表添加 push_token
。
以下是一个使用 to
方法的示例,如果您不想使用配置或迁移。
// ... use NotificationChannels\Expo\ExpoChannel; use NotificationChannels\Expo\ExpoMessage; class CheckInTime extends Notification { // ... public function via($notifiable) { return [ExpoChannel::class]; } public function toExpo($notifiable) { return (new ExpoMessage) ->to('ExponentPushToken[**********************]') ->title("It's time to check in!") ->body('Check in now for us to print your name badge') ->setJsonData(['screen' => 'CheckIn']); } }
可用的消息方法
to(string)
:设置消息的接收者。默认为通知者的push_token
属性。title(string)
:设置消息的标题。body(string)
:设置消息的正文。enableSound()
:启用默认声音播放。disableSound()
:禁用默认声音播放。badge(int)
:将徽章设置为 int 值。(仅限 iOS)setTtl(int)
:设置生存时间值。(仅限 iOS)setChanelId(int)
:设置通知的 chanelId。(仅限 Android)setJsonData(array|string)
:设置通知的额外数据,可以传递一个数组或一个 json 字符串。toArray()
:将消息转换为数组。
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。
测试
$ composer test
安全
如果您发现任何安全相关的问题,请通过电子邮件 andymswick@gmail.com 报告,而不是使用问题跟踪器。
贡献
请参阅 CONTRIBUTING 了解详细信息。
鸣谢
许可证
MIT 许可证(MIT)。请参阅 许可证文件 了解更多信息。