pesakitan22/pusher-push-notifications

Pusher本地推送通知驱动程序。

2.0.1 2017-02-22 15:29 UTC

This package is not auto-updated.

Last update: 2024-09-18 03:49:52 UTC


README

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

此包使您能够通过Laravel 5.4轻松发送Pusher推送通知

内容

安装

您可以通过composer安装此包

composer require dees040/pusher-push-notifications:dev-master

您必须安装服务提供者

// config/app.php
'providers' => [
    ...
    NotificationChannels\PusherPushNotifications\PusherPushNotificationsServiceProvider::class,
],

设置您的Pusher账户

在开始使用此包之前,您应该设置Pusher账户。以下是所需步骤。

  • 登录到https://dashboard.pusher.com/
  • 从侧边栏选择您的应用程序或创建一个新应用程序。
  • 点击“推送通知”标签。
  • 上传您的APNS证书或添加您的GCM API密钥。
  • 现在选择“应用程序密钥”标签。
  • 复制您的app_idkeysecret
  • 更新位于pusher连接下的config/broadcasting.php文件中的值。
  • 现在您已经准备好使用了。

使用

现在您可以在Notification类内的via()方法中使用该通道。

use NotificationChannels\PusherPushNotifications\PusherChannel;
use NotificationChannels\PusherPushNotifications\PusherMessage;
use Illuminate\Notifications\Notification;

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

    public function toPushNotification($notifiable)
    {
        return PusherMessage::create()
            ->iOS()
            ->badge(1)
            ->sound('success')
            ->body("Your {$notifiable->service} account was approved!");
    }
}

可用的消息方法

  • platform(''):接受字符串值iOSAndroid
  • iOS():将平台值设置为iOS。
  • android():将平台值设置为Android。
  • title(''):接受字符串值作为标题。
  • body(''):接受字符串值作为正文。
  • sound(''):接受字符串值作为通知声音文件。请注意,如果您留空,默认声音值将是default
  • icon(''):接受字符串值作为图标文件。(仅限Android)
  • badge(1):接受整数值作为徽章。(仅限iOS)
  • setOption($key, $value):允许您在消息有效载荷中设置任何值。有关更多信息,请在此处查看iOS或在此处查看Android

发送到多个平台

您可以使用withiOS()withAndroid()方法同时向iOS设备和Android设备发送单个消息。

public function toPushNotification($notifiable)
{
    $message = "Your {$notifiable->service} account was approved!";

    return PusherMessage::create()
        ->iOS()
        ->badge(1)
        ->body($message)
        ->withAndroid(
            PusherMessage::create()
                ->title($message)
                ->icon('icon')
        );
}
  • 请注意,iOS是默认平台,这意味着您不需要调用->iOS()
  • 当使用withAndroid()withiOS()时,您不需要定义平台,它将在幕后为您完成。

消息路由

默认情况下,Pusher“兴趣”消息将被定义为使用{notifiable}.{id}约定,例如App.User.1,但是您可以更改这种行为,通过在可通知类方法中包含一个返回兴趣名称的routeNotificationForPusherPushNotifications()

更新日志

请参阅更新日志以获取有关最近更改的更多信息。

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件themsaid@gmail.com联系,而不是使用问题跟踪器。

贡献

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

鸣谢

许可

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