I'm trying to implement safari push notifications on my site using this guide https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/NotificationProgrammingGuideForWebsites/PushNotifications/PushNotifications.html
There is a button on the site and the following JS code:
window.onload = function() { var p = document.getElementById('subscribe'); p.onclick = function() { // Ensure that the user can receive Safari Push Notifications. if ('safari' in window && 'pushNotification' in window.safari) { var permissionData = window.safari.pushNotification.permission('MY_REAL_WEBSITE_PUSH_ID'); checkRemotePermission(permissionData); } }; var checkRemotePermission = function(permissionData) { console.log(permissionData); if (permissionData.permission === 'default') { // This is a new web service URL and its validity is unknown. window.safari.pushNotification.requestPermission( 'MY_REAL_WEBSERVICE_URL', // The web service URL. 'MY_REAL_WEBSITE_PUSH_ID', // The Website Push ID. {}, // Data that you choose to send to your server to help you identify the user. checkRemotePermission // The callback function. ); } else if (permissionData.permission === 'denied') { // The user said 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. } }; }
As a result when I press the button I get request permission.
When I disallow notifications all works as expected: console.log(permissionData);
shows permissionData.permission
equals denied and I can see site as denied at Safari's Preferences -> Notifications section.
But when I allow notification nothing happens. It seems checkRemotePermission
doesn't fire as window.safari.pushNotification.requestPermission
's callback.
Any thoughts?
1 Answers
Answers 1
I had a similar problem in a virtual machine, and found a solution for VMWare.
In the configuration .vmx
file, you need add something like this:
smbios.reflectHost = "TRUE" serialNumber = "RM125589AGW" board-id = "MAC-F22598C8"
0 comments:
Post a Comment