I have created the push package with valid certificate and hosted on server with valid SSL certificate but problem is that javascript always shows the denied message even before prompting to user. I am using the java script code from apple tutorial with valid website push id & webservice url etc
document.body.onload = function() {
// Ensure that the user can receive Safari Push Notifications.
if ('safari' in window && 'pushNotification' in window.safari) {
var permissionData = window.safari.pushNotification.permission('web.com.example.domain');
checkRemotePermission(permissionData);
}
};
var checkRemotePermission = function (permissionData) {
if (permissionData.permission === 'default') {
// This is a new web service URL and its validity is unknown.
window.safari.pushNotification.requestPermission(
'https://domain.example.com', // The web service URL.
'web.com.example.domain', // 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') {
alert('denied');
// The user said no.
}
else if (permissionData.permission === 'granted') {
alert('granted');
// The web service URL is a valid push provider, and the user said yes.
// permissionData.deviceToken is now available to use.
}
};
The problem is that I get 'denied' alert in my javascript , because the permission is denied. The thing is it never asked, nor has it ever asked before. Its not even in my safari preferences.
Why does safari return denied without even asking?