I am trying to implement web notifications for Safari with the following code in the client:
<script>
var pushId = "pushId";
var pushNotification = function () {
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) {
console.log("Chiamo checkRemotePermission");
if (permissionData.permission === 'default') {
window.safari.pushNotification.requestPermission(
'socket url'
pushId,
{},
checkRemotePermission
);
console.log("Requested");
} else if (permissionData.permission === 'denied') {
console.log("denied");
alert("denied");
} else if (permissionData.permission === 'granted') {
console.log("The user said yes, with token: "+ permissionData.deviceToken);
alert(permissionData.deviceToken)
}
};
</script>
<button name="subscribe" value="Activate Notifications" onclick="pushNotification()">Activate Notifications</button>
And on the server side distributed by node.js:
var express = require('express');
var app = express();
var port = process.env.PORT || 3000;
console.log('entering on port: '+port)
app.listen(port);
app.get('/', function(req, res) {
console.log('get');
res.sendfile('index.html');
});
app.post('/v2/pushPackages/web.net.inarrivo.pizzomarinellafs', function(req, res) {
console.log('register');
res.sendfile('pushPackage.zip');
});
app.post(''socket url'/v2/devices/deviceToken/registation/pushId, function(req, res) {
console.log(res)
});
app.post(''socket url'/v2/log', function(req, res) {
console.log(res)
});
Yet I always receive 'denied' and it even seems the back office script is not even touched given no console log is written after the first one. The port on which it is listening is 3000, but I have no idea how to set it on the client side. What is strange is that if I change the url in:
window.safari.pushNotification.requestPermission(
'url2'
pushId,
{},
checkRemotePermission
);
to a dummy server I get the same denied answer, like the server were never connected anyway. May someone help to have this thing working?
<script>
var pushId = "pushId";
var pushNotification = function () {
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) {
console.log("Chiamo checkRemotePermission");
if (permissionData.permission === 'default') {
window.safari.pushNotification.requestPermission(
'socket url'
pushId,
{},
checkRemotePermission
);
console.log("Requested");
} else if (permissionData.permission === 'denied') {
console.log("denied");
alert("denied");
} else if (permissionData.permission === 'granted') {
console.log("The user said yes, with token: "+ permissionData.deviceToken);
alert(permissionData.deviceToken)
}
};
</script>
<button name="subscribe" value="Activate Notifications" onclick="pushNotification()">Activate Notifications</button>
And on the server side distributed by node.js:
var express = require('express');
var app = express();
var port = process.env.PORT || 3000;
console.log('entering on port: '+port)
app.listen(port);
app.get('/', function(req, res) {
console.log('get');
res.sendfile('index.html');
});
app.post('/v2/pushPackages/web.net.inarrivo.pizzomarinellafs', function(req, res) {
console.log('register');
res.sendfile('pushPackage.zip');
});
app.post(''socket url'/v2/devices/deviceToken/registation/pushId, function(req, res) {
console.log(res)
});
app.post(''socket url'/v2/log', function(req, res) {
console.log(res)
});
Yet I always receive 'denied' and it even seems the back office script is not even touched given no console log is written after the first one. The port on which it is listening is 3000, but I have no idea how to set it on the client side. What is strange is that if I change the url in:
window.safari.pushNotification.requestPermission(
'url2'
pushId,
{},
checkRemotePermission
);
to a dummy server I get the same denied answer, like the server were never connected anyway. May someone help to have this thing working?