更改推送管理器订阅中的应用程序服务器密钥 [英] Changing application server key in push manager subscription

查看:45
本文介绍了更改推送管理器订阅中的应用程序服务器密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Service Worker 实现了网络推送通知.我使用特定的应用程序服务器密钥收集了用户订阅.假设如果我们更改应用服务器密钥,那么当我们使用reg.pushManager.getSubscription()"获取订阅时,我们将获得使用旧应用服务器密钥创建的旧订阅信息.如何处理这种情况?如何从用户那里获取新订阅?

I implemented web push notifications using service worker. I collected user subscriptions with a particular application server key. Suppose if we change the application server key, then when we get the subscription using "reg.pushManager.getSubscription()", we will get the old subscription information which was created using the old application server key. How to handle this scenario? How to get the new subscription from the user?

推荐答案

使用 reg.pushManager.getSubscription() 获取订阅并检查当前订阅是否使用新的应用服务器密钥.如果没有,则对现有订阅调用 unsubscribe() 函数并重新订阅.

Get the subscription using reg.pushManager.getSubscription() and check whether current subscription uses the new application server key. If not, then call unsubscribe() function on the existing subscription and resubscribe again.

这篇关于更改推送管理器订阅中的应用程序服务器密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆