Closed Saqib92 closed 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 💙
Git repo with minimal Reproducible Code: https://github.com/Saqib92/cap-push-issue
can you also share the payload you are using for the push notifications?
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();
?>
Fixed it by removing 'click_action' => "ActionPerformed" //Action/Activity - Optional
this line from my my $notifData
this click_action
was the culprit.
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.
Bug Report
Capacitor Version
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.Expected Behavior
ActionPerformed
Listener should Open Application on tapping.Code Reproduction
Issue Repo
Other Technical Details
npm --version
output: 6.14.12node --version
output: v14.16.1pod --version
output (iOS issues only):Additional Context