Onesignal Web Push

Asked

Viewed 186 times

0

Guys I’m trying to use Onesginal Web but it doesn’t work, appears the icon below but does nothing.

Already this all configured in the site "onesignal"

Onesignal is making a call I believe should be in trouble. This passing in Undefined url.

http://localhost/Undefined/Undefined? appid=xxxxxx

` Onesignal Push Notification

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">

    <link rel="manifest" href="manifest.json">

    <!-- <script src="https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js" async="" ></script> -->


    <script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
    <script>
      var OneSignal = window.OneSignal || [];
      OneSignal.push(function() {
        OneSignal.init({
          appId: "XXXXX-XXXXX-XXXX-XXXX",
          autoRegister: false,
          allowLocalhostAsSecureOrigin: true,
          notifyButton: {
            enable: true,
          },
        });
      });
    </script>

`

1 answer

0


Here’s how I handled it. I created on the site onesignal the web push of type "Typical Site" and the functionality to subscribe will only work if your url is "https".

Note: should be added the url that onesignal should point to in "Site url"

If you want to take the userid generated by onesignal, follow the function:

function getUserId() {
    var OneSignal = window['OneSignal'] || [];
    OneSignal.push(function() {
      /* These examples are all valid */
      OneSignal.getUserId(function(userId) {
        console.log("OneSignal User ID:", userId);
      });

      OneSignal.getUserId().then(function(userId) {
        console.log("OneSignal User ID:", userId);
      });
    });
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.