6.2 C
New York
Tuesday, April 1, 2025

javascript – iOS PWA push notification actions (sure/no buttons) not exhibiting – any workaround?


I am attempting to implement push notifications for a PWA. This is the related code snippet utilizing PHP with Minishlink/WebPush:

use MinishlinkWebPushWebPush;
use MinishlinkWebPushSubscription;
$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 right here is the related a part of my serviceworker.js:

self.addEventListener('notificationclick', perform (occasion) {
  occasion.notification.shut();
  let targetUrl="[target URL]";
  if (occasion.motion === 'sure') {
    targetUrl="[URL 1]";
  } else if (occasion.motion === 'no') {
    targetUrl="[URL 2]";
  } else {
    targetUrl="[URL 3]";
  }
  occasion.waitUntil(
    purchasers.matchAll({ kind: 'window', includeUncontrolled: true }).then(windowClients => {
      for (const shopper of windowClients) {
        if (shopper.url === targetUrl && 'focus' in shopper) {
          return shopper.focus();
        }
      }
      if (purchasers.openWindow) {
        return purchasers.openWindow(targetUrl);
      }
    })
  );
});

This setup works completely on Android — the “Sure” and “No” buttons seem and performance appropriately.

Nonetheless, the buttons don’t seem on iOS (tried – Safari+Chrome).

GPT Response –

You are working right into a identified limitation on iOS: As of now, interactive notification actions (like your sure/no buttons) are usually not supported in iOS Safari Progressive Net Apps (PWAs).

Is there any identified workaround or different to attain related performance on iOS?
The issue is important for my app since most of my customers are on iOS, and the sure/no resolution is central to the consumer expertise.

Thanks prematurely!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles