V
V
vista1x2019-07-30 10:04:39
Google Chrome
vista1x, 2019-07-30 10:04:39

Why are push notifications not being delivered?

Good afternoon.
On site X, I implemented push notifications using firebase. Initialization, obtaining a token - everything works. However, there were problems with sending push notifications and their delivery.
The send script looks like this:

$notification = [
  'title' => 'Title',
  'body' => 'Text',
  'click_action' => 'https://site.ru',
];

$ids = [
  // токены
];

$key = '###key###';

$headers = array(
  "Content-Type: application/json",
  "Authorization: key={$key}"
);

$postData = json_encode(array(
  'notification' => $notification,
  'registration_ids' => $ids,
  "priority" => "high"
));

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);

curl_close($ch);

print_r($response);

Sending a push every time gives a different result.
1) It happened that immediately after receiving a token, the first push to it was sent correctly, all subsequent pushes were not delivered.
2) It happens that messages are not delivered to any at all
3) It happens that messages are delivered every time without problems.
4) It happens that out of 10 messages 1-2 are delivered.
At the same time, firebase returns a response without errors, that is, messages leave, but are not delivered to the client.
And on different devices the outcome is different.
Another point: if the push is not delivered, I tried to take his token and send a push to it through an online service (there are many different ones). The bottom line is that everything (most often) is delivered through them without problems.
Actually, the question is: what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kafkiansky, 2019-07-30
@mad_maximus

what am I doing wrong

You take articles from habr and do not read comments to them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question