So, I can't figure this out.
I have the following JavaScript for signing up for push notifciations. (I've put it at the bottom of this question).
I don't get prompted to request permission to allow push notifications, and I get a straight 'denied'.
I've checked in safari preferences, that nothing is blocking notifications, and even logged on as a guest on my Mac.
I can't see any problems in the OSX Console.
On my web server, the log endpoint i.e https://SERVER/v1/log doesn't get hit. I'm logging any requests to this, to a database. I've tested it and the logging is working.
My SERVER is hosted and I haven't got access to the log files. I'm not sure how I can go about resolving this issue.
Anyone got any ideas?
<script>
var pushId = "web.com.myserver";
var subscribe = document.querySelector("#subscribe");
subscribe.addEventListener("click", function(evt) {
pushNotification();
}, false);
var pushNotification = function () {
"use strict";
if ('safari' in window && 'pushNotification' in window.safari) {
var permissionData = window.safari.pushNotification.permission(pushId);
checkRemotePermission(permissionData);
} else {
alert("Push notifications not supported.");
}
};
var checkRemotePermission = function (permissionData) {
"use strict";
if (permissionData.permission === "default") {
console.log("The user is making a decision");
window.safari.pushNotification.requestPermission(
pushId,
{
"id": "123"
},
checkRemotePermission
);
}
else if (permissionData.permission === "denied") {
console.dir(arguments);
}
else if (permissionData.permission === "granted") {
console.log("The user said yes, with token: "+ permissionData.deviceToken);
}
};
</script>