santigp258/expo-notification-channel

为 Laravel 的 Expo 通知驱动程序

v1.0.0 2022-07-20 07:12 UTC

This package is not auto-updated.

Last update: 2024-09-26 15:51:28 UTC


README

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

此包可轻松使用 Laravel 8.x 发送通过 Expo 的通知

内容

安装

使用 Composer 安装此包

composer require santigp258/expo-notification-channel

设置 Expo 服务

如果您使用 Expo 访问令牌,请将其设置在您的环境中。

EXPO_ACCESS_TOKEN=mysecrettoken

使用方法

首先,您需要定义一个方法来检索您的 Expo 推送令牌

class NotifiableModel extends Model {
    // You may pass a single token
    public function routeNotificationForExpo($notification)
    {
        return "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]"
    }
    
    // Or you may return an array of tokens, for example, a user could have multiple devices.
    public function routeNotificationForExpo($notification)
    {
        return $this->installations->pluck('expo_token')->toArray()
    }
}
<?php

namespace App\Notifications;

use App\Models\Message;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\Expo\ExpoChannel;
use NotificationChannels\Expo\ExpoMessage;

class NewMessageNotification extends Notification
{
    use Queueable;

    private Message $message;

    public function __construct(Message $message)
    {
        $this->message = $message;
    }

    public function via($notifiable)
    {
        return [ExpoChannel::class];
    }

    public function toExpo($notifiable)
    {
        return ExpoMessage::create()
            ->title("New Message from {$this->message->from}!")
            ->body($this->message->text)
            ->badge(1);
    }
}

可用的消息方法

更新日志

请参阅 更新日志 了解最近更改的详细信息。

测试

$ composer test

安全性

如果您发现任何与安全性相关的问题,请通过电子邮件 nick@npratley.net 反馈,而不是使用问题跟踪器。

贡献

请参阅 贡献指南 获取详细信息。

致谢

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 获取更多信息。