AngularPWA推送通知不能在除PC浏览器外的其他设备上使用
创始人
2024-10-29 02:00:24
0
  1. 确保使用的浏览器和设备都支持PWA推送通知功能.
  2. 检测您的推送通知配置文件是否正确,包括推送密钥和服务器地址等参数设置.
  3. 确保您的消息推送代码已正确部署到您的PWA应用程序中. 以下是一个基本的Angular PWA推送通知示例代码:

//检查浏览器是否支持serviceWorker if ('serviceWorker' in navigator) { // Register service worker navigator.serviceWorker.register('/ngsw-worker.js').then(registration => { console.log('Service Worker Registered'); //注册 Push Manager并获取推送许可 registration.pushManager .subscribe({ userVisibleOnly: true, applicationServerKey: }) .then(subscription => { console.log('User is subscribed:', subscription); //发送推送消息到订阅的设备 fetch('/push', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(subscription) }); }) .catch(err => { console.log('Failed to subscribe the user: ', err); }); }).catch(error => { console.error('Error during service worker registration:', error); }); }

注意:上述代码仅为示例代码,此代码必须根据您的PWA应用程序的要求进行修改。

相关内容

热门资讯

透视妙计!wejoker开挂(... 透视妙计!wejoker开挂(AApoker提高)果然有辅助教程(哔哩哔哩)1、操作简单,无需wej...
透视总结!hhpoker辅助软... 透视总结!hhpoker辅助软件(WePoKer高级)原来有辅助神器(哔哩哔哩)1、进入游戏-大厅左...
透视指南!hhpoker辅助挂... 透视指南!hhpoker辅助挂(WePoKer养号)一贯真的有辅助技巧(哔哩哔哩)hhpoker辅助...
透视资料!uupoker透视(... 透视资料!uupoker透视(WePoKer私人)总是有辅助方法(哔哩哔哩)uupoker透视是不是...
透视机巧!xpoker怎么作必... 透视机巧!xpoker怎么作必弊(WePoKer游戏)果然真的有辅助插件(哔哩哔哩)1、完成xpok...
透视阶段!wepoker提高好... 透视阶段!wepoker提高好牌率(WPK安装)其实是真的有辅助方法(哔哩哔哩)1、不需要AI权限,...
透视攻略!wepoker有用吗... 透视攻略!wepoker有用吗(WPK安装)一直真的是有辅助软件(哔哩哔哩)小薇(辅助器软件下载)致...
透视法子!wepoker手机版... 透视法子!wepoker手机版辅助(WPK德州局)一贯真的是有辅助app(哔哩哔哩)1)wepoke...
透视阶段!wepoker私人局... 透视阶段!wepoker私人局透视(德普之星介绍)好像真的是有辅助技巧(哔哩哔哩)1、下载好wepo...
透视要领!德普之星辅助器怎么用... 透视要领!德普之星辅助器怎么用(WePoKer黑科技)确实真的是有辅助软件(哔哩哔哩)1、全新机制【...