OSX Push Notifications for Websites - Safari requestPermission callback never called

烂漫一生 提交于 2019-12-24 10:56:11

问题


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.

I'm using SSL, have a certificate from Apple, and have generated the push package file.

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);
  1. The callback function is never called.
  2. No exceptions are thrown.
  3. No POST is made to the server for any success or error.
  4. The website is now listed under System Preferences > Notifications.
  5. The website is not listed under Notifications within Safari Preferences.
  6. Further attempts to requestPermission or query permission are denied instantly.

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.

What could be causing this unusual behaviour?


回答1:


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.

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

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.



来源:https://stackoverflow.com/questions/24596837/osx-push-notifications-for-websites-safari-requestpermission-callback-never-ca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!