如何解决Firefox PushManager订阅不适用于Android
我当前正在使用推送通知。我可以在计算机上使用它,但是不能在手机上使用它!我尝试使用最新版本的Firefox Nightly and Preview。
navigator.serviceWorker.register('service-worker.js').then(function(registration) {
console.log('Before return')
registration.pushManager.permissionState().then(function(state){
console.log("State : " + state)
})
return registration.pushManager.getSubscription().then(async function(subscription) {
if (subscription) {
console.log('Already have a subscription')
return subscription;
}
console.log('Getting vapid key')
const response = await fetch('./subscription');
const vapidPublicKey = JSON.parse(await response.text())['public_key']
console.log(vapidPublicKey)
const convertedvapidKey = urlBase64ToUint8Array(vapidPublicKey);
console.log('Trying to subscribe')
registration.pushManager.permissionState().then(function(state){
console.log("State juste before : " + state)
})
options = {
userVisibleOnly: true,//VisibleOnly: true,applicationServerKey: convertedvapidKey
}
return registration.pushManager.subscribe(options).then(function(pushSubscription) {
console.log(pushSubscription.endpoint);
},function(error) {
console.log(error);
});
});
}).then(function(subscription) {
if (subscription){
console.log('Fetching subscription')
fetch('./subscription',{
method: 'post',headers: {
'Content-type': 'application/json'
},body: JSON.stringify({
subscription: subscription
}),});
}
});
如您所见,在订阅之前,我记录了推送管理器的状态,但这是我的日志:
Before return
State : granted
Getting vapid key
// vapid key
Trying to subscribe
State juste before : granted
DOMException: User denied permission to use the Push API.
我总是会遇到此异常,当被要求允许通知时,我单击允许,并在此特定网站的参数中允许通知。
我使用带有自签名证书的https。我不明白为什么会说用户拒绝使用Push API的权限,而且我不知道该怎么做...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。