clients.openWindow 无法在 iOS PWA 上运行

问题描述 投票:0回答:1

我正在开发一个包含推送通知的渐进式网络应用程序(PWA)。当用户与通知交互时,我使用clients.openWindow 方法打开一个新窗口。但是,我在 iOS 设备上遇到了一个问题,其中 client.openWindow 函数似乎无法按预期工作。 这是我正在使用的代码片段:

if (clients.openWindow) {
  return clients
    .openWindow(onNotificationAction(notification.data))
    .then((e) => console.log(e, 'e'))
    .catch((e) => console.error(e, 'e'));
}
在本例中,notification.data 是“/messages”。 它在 then 方法中记录 null, 'e'。

该代码在其他平台和浏览器上运行良好,但在 iOS 设备上无法正常运行。

我将非常感谢任何有关如何解决此问题并让clients.openWindow 在 iOS PWA 上正常工作的见解或建议。预先感谢您!

尝试了打开新 safari 选项卡的完整网址,但想使用相应的网址打开 pwa。

javascript progressive-web-apps service-worker
1个回答
0
投票
在 Service Worker 中:

self.addEventListener("notificationclick", (e) => { e.notification.close(); e.waitUntil( clients .openWindow(e.notification.data.url) .then((windowClient) => (windowClient ? windowClient.focus() : null)) ); }); self.addEventListener("push", function (event) { const { title, text, url } = event.data.json(); event.waitUntil( self.registration.showNotification(title, { body: text, data: { url: url, }, }) ); });
在 iOS 和 Chrome 上为我工作

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.