问题描述
按照 Apple 文档,允许使用 Safari 浏览器的用户访问网站并获取 Apple 推送通知服务的推送通知.
Following the instructions as per Apple Documentation to allow a user with Safari to visit a website and get Push Notifications for the Apple Push Notification Service.
我正在使用 SSL,拥有 Apple 的证书,并生成了推送包文件.
I'm using SSL, have a certificate from Apple, and have generated the push package file.
Safari 在运行提示 requestPermission
时下载这个,显示用户权限请求提示,但在用户点击批准"时,回调函数永远不会被调用.
Safari downloads this when running the prompt requestPermission
, displays the user permission request prompt, but on the user clicking 'approve', the callback function is never called.
window.safari.pushNotification.requestPermission(url, websitePushID, userInfo, callback);
- 永远不会调用回调函数.
- 不会抛出任何异常.
- 不会对服务器进行任何成功或错误的 POST.
- 该网站现在列在系统偏好设置">通知"下.
- 该网站未列在 Safari 偏好设置中的通知下.
- 进一步尝试请求权限或查询权限会立即被拒绝.
- The callback function is never called.
- No exceptions are thrown.
- No POST is made to the server for any success or error.
- The website is now listed under System Preferences > Notifications.
- The website is not listed under Notifications within Safari Preferences.
- Further attempts to requestPermission or query permission are denied instantly.
重置被拒绝权限的唯一方法是编辑 OSX 的内部 sqllite 文件并在我可以重试请求之前删除 Safari 中的一堆配置文件.
The only way to reset the denied permission is to edits OSXs internal sqllite file and delete a bunch of config files within Safari before I can retry the request.
可能导致这种异常行为的原因是什么?
推荐答案
如果没有您使用的确切 javascript,很难判断,但是您在 Apple 文档中看到的 3 种权限类型是默认的、授予的和拒绝的.
It's hard to judge without the exact javascript you are using, but the 3 permission types that you see in the apple documentaion are default, granted and denied.
如果权限被授予或拒绝,那么用户已经设置了他们是否想要接收这些推送通知.一旦用户拒绝推送通知,Apple 就会决定不能再次询问他们(无需更改设置.)如果他们已经被授予权限,则无需调用 window.safari.pushNotification.requestPermission
If the permission is granted or denied, then the user has already set whether they want to receive these push notifications. Once a user has denied a push notification then Apple has made the decision that they cannot be asked again (without changing settings.) If they already have been granted permission there is no need to call window.safari.pushNotification.requestPermission
您唯一会调用 window.safari.pushNotification.requestPermission 的时间是既未拒绝也未授予权限的情况.只有在这种情况下,您才会想要调用该函数并期望响应来触发回调函数.如果您看到权限请求提示,则表示 requestionPermission 已生效.
The only time that you would call window.safari.pushNotification.requestPermission is when permission has neither been denied nor granted. Only in this case will you want to call the function and expect for a response to trigger the callback function. If you see a permission request prompt it means the requestionPermission has worked.
这篇关于网站的 OSX 推送通知 - 从未调用过 Safari requestPermission 回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!