Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
149 views
in Technique[技术] by (71.8m points)

javascript - Web Push Django in Safari

I am using push notifications in Django, I am using the library https://github.com/safwanrahman/django-webpush

It work correctly in Chrome and Firefox, but in Safari I have a JS error.

   TypeError: undefined is not an object (evaluating 'reg.pushManager.getSuscription')
   -suscribe
   -Anonymus Function

The code is this:

function subscribe(reg) {
  // Get the Subscription or register one
  reg.pushManager.getSubscription().then(
   function(subscription) {
     var metaObj, applicationServerKey, options;
     // Check if Subscription is available
     if (subscription) {
       return subscription;
     }

     metaObj = document.querySelector('meta[name="django-webpush-vapid-key"]');
     applicationServerKey = metaObj.content;
     options = {
     userVisibleOnly: true
     };
     if (applicationServerKey){
       options.applicationServerKey = urlB64ToUint8Array(applicationServerKey)
     }
     // If not, register one
     reg.pushManager.subscribe(options)
       .then(
       function(subscription) {
        postSubscribeObj('subscribe', subscription,
          function(response) {
            // Check the information is saved successfully into server
            if (response.status === 201) {
              // Show unsubscribe button instead
              subBtn.textContent = 'Eliminar suscripción';
              subBtn.disabled = false;
              isPushEnabled = true;
              showMessage('La suscripción se ha eliminado correctamente');
            }
          });
      })
    .catch(
      function() {
        console.log('Subscription error.', arguments)
      })
});
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...