lkaybob / php-fcm-v1

Implementation of Firebase Cloud Messaging HTTP v1 API in PHP
https://packagist.org/packages/lkaybob/php-fcm-v1
MIT License
12 stars 14 forks source link

How to add payload data? #25

Open nutella opened 1 week ago

nutella commented 1 week ago

I've tried with something like:

$data = []; $data['id'] = 10; $data['link'] = 'https://www.github.com'; $client -> build($recipient, $notification, $data);

But got this error: "Got error 'PHP message: PHP Fatal error: Uncaught TypeError: Argument 3 passed to phpFCMv1\Client::build() must be an instance of phpFCMv1\Data or null, array given"

...but $data is an array...

What's wrong?

Thanks.

nutella commented 1 week ago

This seems to work:

$data = new Data(); $foo['id'] = 10; $foo['link'] = 'https://www.github.com'; $bar['data'] = $foo; $data->setPayload($bar); $client -> build($recipient, $notification, $data);