-
Issue with Setting
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
There are two different kinds of FCM Options: the one at the root level of a message only supports the The SDK doesn't actively validate values, but when you use a static code analyser like PHPStan, it would have notified about the wrong field. https://github.com/kreait/firebase-php/blob/7.x/src/Firebase/Messaging/FcmOptions.php d I should add the static analysis information to the documentation, if haven't already 😅. If you don't use an analytics label, you can Safely remove the Let me know if this helps! |
Beta Was this translation helpful? Give feedback.
-
Thanks, but even when I have it like the below, the link is notification is not clickable... $messaging = $this->firebaseService->getMessaging();
$message = CloudMessage::withTarget('token', $token)
->withNotification(['title' => 'Title', 'body' => 'Body'])
->withWebPushConfig(WebPushConfig::fromArray([
'notification' => [
'title' => 'Title',
'body' => 'Body',
'icon' => 'icon.png'
],
'fcm_options' => [
'link' => 'https://your-link.com'
]
]))
;
$messaging->send($message); |
Beta Was this translation helpful? Give feedback.
-
Okay, so after further review I was finally able to get to the bottom of this. The php code now looks like this: $messaging = $this->firebaseService->getMessaging();
$message = CloudMessage::withTarget('token', $token)
->withNotification(['title' => 'Title', 'body' => 'Body'])
->withWebPushConfig(WebPushConfig::fromArray([
'notification' => [
'title' => 'Title',
'body' => 'Body',
'icon' => 'icon.png'
],
'fcm_options' => [
'link' => 'http://localhost/test'
]
]));
$messaging->send($message); my main "issue" was with the sw js not set correctly, now it looks like the below and it works great! self.addEventListener('notificationclick', function(event) {
// Access the click_action URL from the notification data
const clickAction = event.notification.data.FCM_MSG.notification.click_action;
console.log('Notification click_action URL:', clickAction);
// Close the notification
event.notification.close();
// Open the click_action URL in a new window
event.waitUntil(
clients.openWindow(clickAction)
);
}); obviously still needs refinement, but this works |
Beta Was this translation helpful? Give feedback.
Okay, so after further review I was finally able to get to the bottom of this.
The php code now looks like this:
my main "issue" was wi…