0

I'm trying to implement push notifications for a PWA. Here's the relevant code snippet using PHP with Minishlink/WebPush:

use Minishlink\WebPush\WebPush;
use Minishlink\WebPush\Subscription;
$webPush = new WebPush($auth);

        $payload = json_encode([
            'title' => 'Booking Reminder',
            'body' => 'Do you want to book now?',
            'icon' => 'at.png',
            'url' => '', // optional default fallback
            'actions' => [
                [
                    'action' => 'yes',
                    'title' => 'Yes',
                    'icon' => 'yes.png'
                ],
                [
                    'action' => 'no',
                    'title' => 'No',
                    'icon' => 'no.png'
                ]
            ]
        ]);
        $webPush->queueNotification($subscription, $payload);

And here is the relevant part of my serviceworker.js:

self.addEventListener('notificationclick', function (event) {
  event.notification.close();
  let targetUrl = '[target URL]';
  if (event.action === 'yes') {
    targetUrl = '[URL 1]';
  } else if (event.action === 'no') {
    targetUrl = '[URL 2]';
  } else {
    targetUrl = '[URL 3]';
  }
  event.waitUntil(
    clients.matchAll({ type: 'window', includeUncontrolled: true }).then(windowClients => {
      for (const client of windowClients) {
        if (client.url === targetUrl && 'focus' in client) {
          return client.focus();
        }
      }
      if (clients.openWindow) {
        return clients.openWindow(targetUrl);
      }
    })
  );
});

This setup works perfectly on Android — the "Yes" and "No" buttons appear and function correctly.

However, the buttons do not appear on iOS (tried - Safari+Chrome).

GPT Response -

You're running into a known limitation on iOS: As of now, interactive notification actions (like your yes/no buttons) are not supported in iOS Safari Progressive Web Apps (PWAs).

Is there any known workaround or alternative to achieve similar functionality on iOS? The problem is critical for my app since most of my users are on iOS, and the yes/no decision is central to the user experience.

Thanks in advance!

3
  • PWAs are not a good approach for iOS. They have limitations, such as this one. If you want to use web technologies you could look at React Native Commented Apr 1 at 12:41
  • client demands pwa Commented Apr 3 at 13:29
  • Then you can't have actionable notifications on iOS. Commented Apr 3 at 20:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.