yieldstudio/laravel-expo-notifier

使用 Laravel 轻松发送 Expo 通知。

0.0.15 2024-06-14 09:56 UTC

This package is auto-updated.

Last update: 2024-09-14 10:34:53 UTC


README

使用 Laravel 轻松管理 Expo 通知。支持批量通知。

Latest Version GitHub Workflow Status Total Downloads

主版本零 (0.y.z) 用于初始开发。任何内容都可能在任何时候发生变化。公共 API 应不被视为稳定。

安装

composer require yieldstudio/laravel-expo-notifier

配置

您必须使用以下命令发布配置文件:

php artisan vendor:publish --provider="YieldStudio\LaravelExpoNotifier\ExpoNotificationsServiceProvider" --tag="expo-notifications-config" --tag="expo-notifications-migration"

可用环境变量

  • EXPO_PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT : 设置批量请求中发送的最大通知数。官方文档说明限制应为 100,但实际上可能会失败。您可以通过设置小于 100 的值来调整它。

使用方法

发送通知

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use YieldStudio\LaravelExpoNotifier\ExpoNotificationsChannel;
use YieldStudio\LaravelExpoNotifier\Dto\ExpoMessage;

class NewSampleNotification extends Notification
{
    public function via($notifiable): array
    {
        return [ExpoNotificationsChannel::class];
    }

    public function toExpoNotification($notifiable): ExpoMessage
    {
        return (new ExpoMessage())
            ->to([$notifiable->expoTokens->value])
            ->title('A beautiful title')
            ->body('This is a content')
            ->channelId('default');
    }
}

命令使用

发送数据库中的挂起通知

php artisan expo:notifications:send

清除过期的令牌

php artisan expo:tickets:check

您可以为这些命令创建计划来执行。

批量支持

您可以在下一个批次中发送通知

(new ExpoMessage())
    ->to([$notifiable->expoTokens->value])
    ->title('A beautiful title')
    ->body('This is a content')
    ->channelId('default')
    ->shouldBatch();

别忘了安排 expo:notifications:send 命令。

单元测试

要运行测试,只需运行 composer installcomposer test

更新日志

有关最近更改的更多信息,请参阅 更新日志

贡献

有关详细信息,请参阅 贡献指南

安全性

如果您发现有关安全的错误,请通过 contact@yieldstudio.fr 邮件联系,而不是使用问题跟踪器。

鸣谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件