brozot / Laravel-FCM

Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).
MIT License
889 stars 409 forks source link

Notification priority is undefined #172

Open jf-ouellette opened 4 years ago

jf-ouellette commented 4 years ago

Hi!

I'm trying to show heads-up notifications on an Android device and it seems to require the notification priority for SDK < 26.

I am setting the priority with the OptionsBuilder, but when I receive the notification in frontend, the _priority attribute is set to undefined.

I'm not sure if the problem is with laravel-fcm or if something happens between the moment my notification is sent to FCM and the moment I log it in my application.

Here's my code:

public function send($notifiable, Notification $notification): void
{
    $this->notifiable = $notifiable;
    $this->notification = $notification;
    $this->data = $this->getData();

    $tryCount = 0;
    $notification = $this->buildNotification();
    $topic = $this->buildTopic();
    $options = $this->buildOptions();

    do {
        $tryCount++;
       $response = FCM::sendToTopic($topic, $options, $notification, null);
    } while ($response->shouldRetry() && $tryCount <= 5);
}
protected function buildOptions(): Options
{
    return (new OptionsBuilder())
        ->setPriority(OptionsPriorities::high)
        ->build();
}

Am I missing something? Thank you!

jeremiahsherrill commented 4 years ago

I hope you already found the answer.

$optionBuilder->setPriority('high'); is how you set priority

jf-ouellette commented 4 years ago

@jeremiahsherrill Actually, it's already what I'm doing. OptionsPriorities::high returns the string high. Unfortunately, it is not working for some reason...