【问题标题】:Web Push Notification working on Android but not on IOSWeb 推送通知在 Android 上工作,但在 IOS 上不工作
【发布时间】:2021-03-17 04:34:37
【问题描述】:

我正在尝试使用此代码从网络应用程序向手机发送推送通知。

function notify(mess) {
  navigator.serviceWorker.register('sw.js');
  Notification.requestPermission(function (result) {
    if (result === 'granted') {
      navigator.serviceWorker.ready.then(function (registration) {
        registration.showNotification('Valet Pra', {
          body: mess,
          icon: './WebsiteLogo.png',
          vibrate: [200, 100, 200, 100, 200, 100, 200],
          tag: 'vibration-sample',
        });
      });
    }
  });
}

sw.js 文件为空。

我使用 chrome 浏览器在我的 Android 手机上收到通知。

但是,当我在 iPhone 的 IOS(Safari 和 Chrome)上尝试相同操作时,通知不会创建。

请帮帮我。我也愿意尝试任何其他方法。

【问题讨论】:

    标签: ios push-notification safari service-worker web-push


    【解决方案1】:

    iOS 版 Chrome 使用 safari webkit。所以你必须在 Notification api 上查看 webkit 开发状态:

    https://webkit.org/status/

    您可以支持此功能请求: https://bugs.webkit.org/show_bug.cgi?id=182566

    这仍然无法在 ios 上运行(查看 safari ios 专栏):

    https://developer.mozilla.org/en-US/docs/Web/API/notification#browser_compatibility

    https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification#browser_compatibility

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-04
      • 2016-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多