Safari浏览器推送通知返回否认不求回报 [英] Safari push notifications return denied without asking

查看:377
本文介绍了Safari浏览器推送通知返回否认不求回报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去使用新的推送通知在Safari。我用下面的代码片断:

Im trying to use the new push notifications in Safari. I'm using the following snippet:

var checkRemotePermission = function (permissionData) {
  if (permissionData.permission === 'default') {
      // This is a new web service URL and its validity is unknown.
      console.log("default");
      window.safari.pushNotification.requestPermission('https://website.com/','web.com.website.notify',{uid: "TEST"},checkRemotePermission);
  }
  else if (permissionData.permission === 'denied') {
      // The user said no.
      console.log("no");
  }
  else if (permissionData.permission === 'granted') {
      // The web service URL is a valid push provider, and the user said yes.
      // permissionData.deviceToken is now available to use.
      console.log("yes");
  }
};

if ('safari' in window && 'pushNotification' in window.safari) {
    var permissionData = window.safari.pushNotification.permission('web.com.website.notify');
    checkRemotePermission(permissionData);
}else{
  alert("This feature is only available on Mac OS X safari")
}

问题是,我得到没有在我的JavaScript控制台,因为许可拒绝。问题是它从来没有问过,也从未问过。它甚至没有在我的Safari浏览器preferences。

The problem is that I get no in my javascript console, because the permission is denied. The thing is it never asked, nor has it ever asked before. Its not even in my safari preferences.

为什么Safari浏览器返回拒绝,甚至没有要求?

Why does safari return denied without even asking?

推荐答案

在本地测试的时候,因为你是从测试地址不是部分可能发生此错误 allowedDomains 阵在该网站的 pushPackage 。对于 https://zeropush.com ,我们增加了主机 lvh.me 我们的 pushPackage 跑在服务器上的端口 80 ,而我们正在实施的Safari推送通知。然后,在 lvh.me 访问您的网站的发展,事情应该表现正常。

This error can happen when testing locally because the address you are testing from isn't part of the allowedDomains array in the site's pushPackage. For https://zeropush.com, we added the host lvh.me to our pushPackage and ran the server on port 80, while we were implementing safari push notifications. You then access your development site at lvh.me and things should behave normally.

您也应该实现在Safari浏览器推送通知的文档中描述你的网站日志的端点,这样就可以得到任何错误日志信息,帮助您进行调试。

You should also implement the logging endpoint for your site described in the safari push notification docs so that you can get any error log information to help you in debugging.

我也写了有关实现Safari浏览器推送通知是有些红宝石中心的职位,但可能会使用。的https://zeropush.com/blog/implementing-safari-push-notifications-in-osx-mavericks.

I also wrote a post about implementing safari push notifications that is somewhat ruby centric, but may be of use. https://zeropush.com/blog/implementing-safari-push-notifications-in-osx-mavericks.

这篇关于Safari浏览器推送通知返回否认不求回报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆