ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.45k stars 977 forks source link

bug: Push Notification ActionPerformed not triggering #4963

Closed Saqib92 closed 2 years ago

Saqib92 commented 2 years ago

Bug Report

Capacitor Version

 Capacitor Doctor

Latest Dependencies:

  @capacitor/cli: 3.2.0
  @capacitor/core: 3.2.0
  @capacitor/android: 3.2.0
  @capacitor/ios: 3.2.0

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/android: 3.0.2
  @capacitor/cli: 3.0.2
  @capacitor/core: 3.0.2

[success] Android looking great! 👌

Platform(s)

Android

Current Behavior

Push Notifications ActionPerformed listener not working when sending notification from my server. but it is working when sending From Firebase Console.

PushNotifications.addListener('pushNotificationActionPerformed',
  (action: ActionPerformed) => {
    console.log('new notif action', action);
  }
);

Expected Behavior

ActionPerformed Listener should Open Application on tapping.

Code Reproduction

Issue Repo

Other Technical Details

npm --version output: 6.14.12

node --version output: v14.16.1

pod --version output (iOS issues only):

Additional Context

Ionitron commented 2 years ago

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks! Ionitron 💙

Saqib92 commented 2 years ago

Git repo with minimal Reproducible Code: https://github.com/Saqib92/cap-push-issue

jcesarmobile commented 2 years ago

can you also share the payload you are using for the push notifications?

Saqib92 commented 2 years ago

Below is my Example Server Code (PHP):

<?php
function sendFCM() {
  // FCM API Url
  $url = 'https://fcm.googleapis.com/fcm/send';

  // Put your Server Key here
  $apiKey = "";

  // Compile headers in one variable
  $headers = array (
    'Authorization:key=' . $apiKey,
    'Content-Type:application/json'
  );

  // Add notification content to a variable for easy reference
  $notifData = [
    'title' => "Test Title",
    'body' => "Test notification body",
    //  "image": "url-to-image",//Optional
    'click_action' => "ActionPerformed" //Action/Activity - Optional
  ];

  $dataPayload = ['to'=> 'My Name', 
  'points'=>80, 
  'other_data' => 'This is extra payload'
  ];

  // Create the api body
  $apiBody = [
    'notification' => $notifData,
    'data' => $dataPayload, //Optional
    'time_to_live' => 600, // optional - In Seconds
    //'to' => '/topics/mytargettopic'
    //'registration_ids' = ID ARRAY
    'to' => "erorcOM3R3CjCkRO2VXwcI:APA91bGX56MA3YEN5IXy9zqpfIR0uXJjGLbvgcEAYLKmKJ0nM05CtQ-AWYp0k6Tx0NQW62N4WD_aBK63bGtF2x6Bz7uOcm5y3ZNKL4x9fG3-691kNZCx8dRxg7TYkggD-tvbaGWjnHZ5",
    'priority'=> 'high'
  ];

  // Initialize curl with the prepared headers and body
  $ch = curl_init();
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt ($ch, CURLOPT_POST, true);
  curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt ($ch, CURLOPT_POSTFIELDS, json_encode($apiBody));

  // Execute call and save result
  $result = curl_exec($ch);
  print($result);
  // Close curl after call
  curl_close($ch);

  return $result;
}
sendFCM();
?>
Saqib92 commented 2 years ago

Fixed it by removing 'click_action' => "ActionPerformed" //Action/Activity - Optional this line from my my $notifData this click_action was the culprit.

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.