OneSignal hello-world 网页 - 无通知

OneSignal hello-world webpage - no notification

我在这个看似非常简单但进展为 0 的问题上花费了令人尴尬的长时间。在这一点上我非常绝望,所以如果有人可以查看我写的简短示例,我将不胜感激。

我正在尝试做的事情:使用 OneSignal 的 Web Push SDK 发送推送通知。

~/Desktop/OneSignal-Browser-Example 中的文件:

index.html

<head>
    <title>OneSignal Example</title>
    <link rel="manifest" href="/manifest.json">
    <script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
    <script>
        var OneSignal = window.OneSignal || [];
        OneSignal.push(["init", {
          appId: "518e60ef-8b73-4852-8172-61cb170dce00",
          autoRegister: true,
          notifyButton: {
            enable: true /* Set to false to hide */
          }
        }]);
        console.log("Test");
    </script>
    <h1>LOADED</h1>
</head>

manifest.json

{
  "name": "OneSignal Example",
  "short_name": "OneSignalExample",
  "start_url": "/",
  "display": "standalone",
  "gcm_sender_id": "482941778795"
}

OneSignalSDKWorker.js

importScripts('https://cdn.onesignal.com/sdks/OneSignalSDK.js');

OneSignalSDKUpdaterWorker.js

importScripts('https://cdn.onesignal.com/sdks/OneSignalSDK.js');

cert.pem

key.pem

我使用 /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --ignore-certificate-errors 启动了 Google Chrome,并使用 http-server --ssl --p 8081 ~/Desktop/OneSignal-Browser-Example 在端口 8081 上设置了一个 https 服务器。

附件是跟踪日志的屏幕截图。

我认为我们能够通过我们的支持渠道帮助您解决问题。

问题是特定配置不匹配:uPaymeiFixit 已将 manifest.json 文件的 gcm_sender_id 属性 修改为不正确的值;他在此更改后订阅并使用不匹配的 GCM 发件人 ID 注册了他的用户,这导致即使其他所有内容都正确也无法发送通知。

这个问题的解决方案是:

  1. Correct gcm_sender_id 值。
  2. Reset his site data and cache 以新用户身份再次测试。

他能够在这些更改后立即收到通知。