Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
Error con 'click_action' para enviar notificación

Estoy tratando de enviar una notificación push con PHP + Firebase. Recibo bien la notificación, pero el evento de 'acción de clic' no funciona. Cuando hago clic en la notificación, desaparece y no me redirige a la PWA.

¿Usted me podría ayudar?

Archivo enviarNotificación.php

 $severKey="MY_KEY"; $url="https://fcm.googleapis.com/fcm/send"; $message = "Test message"; $tokenId="MY_TOKEN"; $icon="MY_ICON"; $favicon = "FAVICON"; $field=array( 'data'=>array( 'notification'=>array( 'title'=>'Notify', 'body'=>$message, 'icon'=>$icon, 'badge' => $favicon, 'click_action' => 'https://www.google.es' //Here the url of my app ) ), 'to'=>$tokenId ); $fields=json_encode($field); $header=array( 'Authorization: key='.$severKey, 'Content-Type: application/json' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); $result=curl_exec($ch); echo $result; curl_close($ch);

Parte de mi archivo firebase-messaging-sw.js

 importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-app.js'); importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-messaging.js'); firebase.initializeApp(firebaseConfig); const messaging = firebase.messaging(); messaging.onBackgroundMessage(function(payload) { console.log('[firebase-messaging-sw.js] Received background message ', payload); const {title, ...options}=JSON.parse(payload.data.notification); self.registration.showNotification(title, options); });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!