Hello all, I'm building a web application in ASP.NET MVC (.NET Framework 4.7.2), from this web app I need to send push notifications to users. For the ones who are logged in with windows/android, everything works as expected, but I can't manage to get it work on the apple side.
If I use the same methods to subscribe to push notifications, it shows me the popup that asks the user to enable push notifications, and then I get an endpoint like this:
https://web.push.apple.com/QKC1Muic0H7...
It doesn't work using this (taking the part after https://web.push.apple.com/
), I keep getting "Bad device token" (trying to send the notification via APNS).
Then I found out that there is another method to register the device from the frontend, and this one should give me the real device token:
window.safari.pushNotification.requestPermission
But this one doesn't show me the popup, it gives me "denied" without a reason.
I'm trying to a test application which is here https://pwa.vctplanner.it, the web push id is web.it.vctplanner, I created a push package downloadable from POST https://pwa.vctplanner.it/api/v2/PushPackages/web.it.vctplanner, and the code from the frontend is this:
function registerSafariPush() {
// Controlla se Safari Push Notifications è disponibile
if (!('safari' in window) || !('pushNotification' in window.safari)) {
console.log("Safari Push Notifications non supportate su questo browser.");
return;
}
// Il tuo Website Push ID registrato su Apple Developer
var websitePushId = "web.it.vctplanner";
// Controlla lo stato della permission
var permissionData = window.safari.pushNotification.permission(websitePushId);
switch (permissionData.permission) {
case 'default': // L'utente non ha ancora deciso
window.safari.pushNotification.requestPermission(
'https://pwa.vctplanner.it', // URL del server che serve il Push Package
websitePushId,
{}, // dati opzionali da inviare al server
function (permission) {
if (permission.permission === 'granted') {
console.log("Notifiche push abilitate!");
sendSubscriptionToServer({ endpoint: permission.deviceToken });
} else {
console.log("Notifiche push non abilitate dall'utente.");
}
}
);
break;
case 'denied': // L'utente ha negato
console.log("Notifiche push negate.");
break;
case 'granted': // L'utente ha già autorizzato
console.log("Notifiche push già autorizzate.");
sendSubscriptionToServer({ endpoint: permissionData.deviceToken });
break;
}
}
Any suggestions of what I'm missing? Is there a complete guide to how generate the push package?
Thank you