【问题标题】:Laravel Web Push notification using edujugon push-notification使用 edujugon 推送通知的 Laravel Web 推送通知
【发布时间】:2018-11-17 05:31:56
【问题描述】:

我的项目有问题。我正在使用 edujugon 推送通知来推送我的应用程序的推送通知,我成功地为 android、ios 设备创建了带有标题、正文的推送通知。但是当我将通知集成到我的网络设备中时,它不会显示标题和正文,而是显示the site is upgrated in backend。另外我想在我的网络通知中设置一个 url。但是不知道怎么弄。

这是我的代码

public static function sendPushNotification($devices, $pushData, $partner = false) {

    $android = $devices->where('type', 2)->pluck('token')->all();
    if (!empty($android)) {
        $push = new PushNotification('fcm');

        $push->setMessage(
            [
                'data' => $pushData,
            ]
        )
            ->setDevicesToken($android)
            ->send();
    }

    $ios = $devices->where('type', 1)->pluck('token')->all();

    if (!empty($ios)) {
        $push = new PushNotification('apn');

        $feedback = $push->setMessage(
                [
                    'aps' => [
                        'alert' => [
                            'title' => $pushData['title'],
                            'body' => $pushData['body'],
                        ],
                        'sound' => 'default',
                        'badge' => 1
                    ],
                    'data' => $pushData
                ]
        )->setDevicesToken($ios)->send()->getFeedback();
    }

    $web = $devices->where('type', 3)->pluck('token')->all();
    if (!empty($web)) {
        $push = new PushNotification('fcm');

        $push->setMessage($pushData)->setDevicesToken($web)->send();
    }
}

而我的推送数据是

$pushData = [
    'title' => 'Test',
    'body' => 'Test',
];

请帮我解决这个问题

【问题讨论】:

    标签: android ios laravel push-notification web-push


    【解决方案1】:

    你应该写这个

    if (!empty($web)) {
                $push = new PushNotification('fcm');
    
                $push->setMessage(
                    [
                        'notification' => $pushData,
                    ]
                )->setDevicesToken($web)->send();
            }
    

    希望这能解决您的问题。

    【讨论】:

      猜你喜欢
      • 2022-07-16
      • 2021-06-11
      • 2018-02-17
      • 2017-03-16
      • 2015-05-12
      • 1970-01-01
      • 2017-11-12
      • 1970-01-01
      • 2015-08-19
      相关资源
      最近更新 更多