我正在尝试使用codeigniter多语言开发PWA。我们已将manifest.json和service-worker.js放在带有index.php的根路径中。
我相信codeigniter正在另一条路径中搜索服务人员。多语言重定向正在影响它吗?
错误:未检测到匹配的服务程序。您可能需要重新加载页面
Manifest.json
{
"name": "Project",
"short_name": "Project",
"theme_color": "#359daf",
2background_color": "#359DAF",
"display": "standalone",
"orientation": "portrait",
"Scope": "/",
"start_url": "/",
"icons": [
{
"src": "assets/img/icons/icon-72x72.png",
"sizes": "72x72",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-96x96.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-144x144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-152x152.png",
"sizes": "152x152",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-384x384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"splash_pages": null
}
注册服务人员
var url = window.location.href;
var swLocation = '/sw.js';
var swReg;
if ( navigator.serviceWorker ) {
window.addEventListener('load', function() {
navigator.serviceWorker.register( swLocation ).then( function(reg){
swReg = reg;
swReg.pushManager.getSubscription();
});
});
}
答案 0 :(得分:0)
您的Service Worker正确的文件名是什么? service-worker.js 或 sw.js
如果文件名为 service-worker.js ,那么您必须调用正确的名称
var swLocation = '/service-worker.js';