laravel-notification-channels / pusher-push-notifications

Pusher Beams notifications channel for Laravel
http://laravel-notification-channels.com
MIT License
271 stars 67 forks source link

Options is missing #48

Closed urumo closed 2 years ago

urumo commented 4 years ago

Hi, I'm using setOptions method to send options to my app, but in my app I don't receive the field of options, how can this be solved?

heres my code in react native:

const handleNotification = notification => {
    console.log(notification, 'notification')
}

and here is the laravel part:

public function via($notifiable)
{
    return [PusherChannel::class];
}
public function toPushNotification($notifiable)
{
    $message = "You have a new message << {$this->title} >>";
    if ($this->date == now()->format('Y-m-d'))
    {
        $body = json_encode(some json);
    }else{
        $body = json_encode(some other json);
    }
    $d = PusherMessage::create()
        ->iOS()
        ->icon(url(public_path('img/icons/Messages.png')))
        ->badge(1)
        ->title($message)
        ->sound('success')
        ->setOption('id',1)
        ->body($body)->withAndroid(
            PusherMessage::create()
                ->setOption('id',1)
                ->body($body)
                ->title($message)
                ->icon(url(public_path('img/icons/Messages.png')))
        );
    dd($d);
}
andregce commented 3 years ago

To send options to your app you need to nest it inside the proper field inside the payload. This is what I am doing on my app:

return PusherMessage::create()

            ->android()

            ->title($title)

            ->body($body)

            ->setOption('fcm.data.%MY_META_DATA_FIELD%', '%META_DATA%')

            ->withiOS(

                    PusherMessage::create()

                ->badge(1)

                ->body($title)

                ->setOption('apns.data.%MY_META_DATA_FIELD%', '%META_DATA%')

            );