Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel Expo推送通知-在Android上未收到通知_Laravel_Notifications_Expo - Fatal编程技术网

Laravel Expo推送通知-在Android上未收到通知

Laravel Expo推送通知-在Android上未收到通知,laravel,notifications,expo,Laravel,Notifications,Expo,我对拉雷维尔很陌生,找不到任何图书馆的实际例子。 我想创建一个简单的欢迎通知 我的通知如下所示: <?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\Exp

我对拉雷维尔很陌生,找不到任何图书馆的实际例子。 我想创建一个简单的欢迎通知

我的通知如下所示:

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\ExpoPushNotifications\ExpoChannel;
use NotificationChannels\ExpoPushNotifications\ExpoMessage;

class WelcomeNotification extends Notification
{
    use Queueable;

    public function __construct(){
    }

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

    public function toExpoPush($notifiable)
    {
        return ExpoMessage::create()
            ->badge(1)
            ->title("Hello World!")
            ->enableSound()
            ->body("Hello World!");
    }

    public function toArray($notifiable)
    {
        return [
        ];
    }
}
    public function toArray()
    {

        $returnArray = [
            'title'     =>  $this->title,
            'body'      =>  $this->body,
            'sound'     =>  $this->sound,
            'badge'     =>  $this->badge,
            'ttl'       =>  $this->ttl,
            'channelId' => $this->channelId,
            'data'      => $this->jsonData,
        ];

        if (strtolower($this->channelId) == 'default' || $this->channelId == '') {
            unset($returnArray['channelId']);
        }

        return $returnArray;
    }
我没有收到通知。当使用世博会通知工具时,它会按预期工作


你能解释一下我做错了什么吗?

我知道了。问题是,库laravel exponent push notifications正在将没有消息通道的所有通知发送到通道“Default”

因此,如果我在设备上创建消息通道“Default”,它就会起作用

或者,还有两种选择:

选项1: 在设备上创建消息通道

import { Notifications } from 'expo';

    if (Platform.OS === 'android') {
        await Notifications.createChannelAndroidAsync('chat-messages', {
            name: 'Chat messages',
            sound: true,
        });
    }
  • 发送通知
  • 通知应包含在设备上注册的消息通道:
  • 选项2: 更改文件
    NotificationChannels\expoothNotifications中的toArray()-方法\
    ExpoMessage.php
    到类似以下内容:

    <?php
    
    namespace App\Notifications;
    
    use Illuminate\Bus\Queueable;
    use Illuminate\Notifications\Notification;
    use NotificationChannels\ExpoPushNotifications\ExpoChannel;
    use NotificationChannels\ExpoPushNotifications\ExpoMessage;
    
    class WelcomeNotification extends Notification
    {
        use Queueable;
    
        public function __construct(){
        }
    
        public function via($notifiable)
        {
            return [ExpoChannel::class];
        }
    
        public function toExpoPush($notifiable)
        {
            return ExpoMessage::create()
                ->badge(1)
                ->title("Hello World!")
                ->enableSound()
                ->body("Hello World!");
        }
    
        public function toArray($notifiable)
        {
            return [
            ];
        }
    }
    
        public function toArray()
        {
    
            $returnArray = [
                'title'     =>  $this->title,
                'body'      =>  $this->body,
                'sound'     =>  $this->sound,
                'badge'     =>  $this->badge,
                'ttl'       =>  $this->ttl,
                'channelId' => $this->channelId,
                'data'      => $this->jsonData,
            ];
    
            if (strtolower($this->channelId) == 'default' || $this->channelId == '') {
                unset($returnArray['channelId']);
            }
    
            return $returnArray;
        }
    
    当在没有频道的情况下向expo应用程序发送通知时,expo将自动创建频道,您将收到通知

    更新 另外,不要忘记在Laravel中注册用户,以便能够接收推送通知。您可以在自定义方法或提供的方法中执行此操作

    可以在以下文件中找到(也可以更改)路由:
    vendor\alymosul\laravel exponent push notifications\src\Http\routes.php

    您好,您能帮我了解详细信息吗,我已经完成了第一个选项,现在我还没有收到任何通知。您打算如何在上述代码中使用Expo push token向特定设备发送通知?迁移后如何获得push token并在向特定设备发送通知时使用它?我不知道该怎么做,而且提供的代码没有包含任何对任何键的引用。。。非常感谢。
        public function toArray()
        {
    
            $returnArray = [
                'title'     =>  $this->title,
                'body'      =>  $this->body,
                'sound'     =>  $this->sound,
                'badge'     =>  $this->badge,
                'ttl'       =>  $this->ttl,
                'channelId' => $this->channelId,
                'data'      => $this->jsonData,
            ];
    
            if (strtolower($this->channelId) == 'default' || $this->channelId == '') {
                unset($returnArray['channelId']);
            }
    
            return $returnArray;
        }