Installation 服务人员不';t安装仅添加到主屏幕
我正在尝试将pwa安装到我的移动设备上。我只能添加到主屏幕。有人知道为什么会发生这种情况吗?要使您的PWA可安装,您需要满足以下要求:Installation 服务人员不';t安装仅添加到主屏幕,installation,service-worker,progressive-web-apps,Installation,Service Worker,Progressive Web Apps,我正在尝试将pwa安装到我的移动设备上。我只能添加到主屏幕。有人知道为什么会发生这种情况吗?要使您的PWA可安装,您需要满足以下要求: 填写正确字段的web清单 要从安全(HTTPS)域提供服务的网站 表示设备上应用程序的图标 服务人员向fetch eventhandler注册,以使应用程序脱机工作(目前仅适用于Android的chrome需要) 您必须在index.html的节中包含清单文件,如下所示 <link rel="manifest" href="name.webma
- 填写正确字段的web清单
- 要从安全(HTTPS)域提供服务的网站
- 表示设备上应用程序的图标
- 服务人员向fetch eventhandler注册,以使应用程序脱机工作(目前仅适用于Android的chrome需要)
<link rel="manifest" href="name.webmanifest">
现在,当浏览器找到满足所有要求的清单文件时,它将触发BeforeInstall提示符,因此您必须显示A2HS对话框
注:
- 不同的浏览器具有不同的安装条件,或触发BeforeSinstallPrompt事件的条件
- 从Android上的Chrome 68开始(2018年7月稳定),Chrome将不再显示添加到主屏幕的横幅。如果网站符合添加到主屏幕的标准,Chrome将显示迷你信息栏
<button class="add-button">Add to home screen</button>
现在在注册服务人员的JS文件中添加以下代码
let deferredPrompt;
//reference to your install button
const addBtn = document.querySelector('.add-button');
//We hide the button initially because the PWA will not be available for
//install until it follows the A2HS criteria.
addBtn.style.display = 'none';
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
// Update UI to notify the user they can add to home screen
addBtn.style.display = 'block';
addBtn.addEventListener('click', (e) => {
// hide our user interface that shows our A2HS button
addBtn.style.display = 'none';
// Show the prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the A2HS prompt');
} else {
console.log('User dismissed the A2HS prompt');
}
deferredPrompt = null;
});
});
});
要使PWA可安装,您需要满足以下要求:
- 填写正确字段的web清单
- 要从安全(HTTPS)域提供服务的网站
- 表示设备上应用程序的图标
- 服务人员向fetch eventhandler注册,以使应用程序脱机工作(目前仅适用于Android的chrome需要)
<link rel="manifest" href="name.webmanifest">
现在,当浏览器找到满足所有要求的清单文件时,它将触发BeforeInstall提示符,因此您必须显示A2HS对话框
注:
- 不同的浏览器具有不同的安装条件,或触发BeforeSinstallPrompt事件的条件
- 从Android上的Chrome 68开始(2018年7月稳定),Chrome将不再显示添加到主屏幕的横幅。如果网站符合添加到主屏幕的标准,Chrome将显示迷你信息栏
<button class="add-button">Add to home screen</button>
现在在注册服务人员的JS文件中添加以下代码
let deferredPrompt;
//reference to your install button
const addBtn = document.querySelector('.add-button');
//We hide the button initially because the PWA will not be available for
//install until it follows the A2HS criteria.
addBtn.style.display = 'none';
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
// Update UI to notify the user they can add to home screen
addBtn.style.display = 'block';
addBtn.addEventListener('click', (e) => {
// hide our user interface that shows our A2HS button
addBtn.style.display = 'none';
// Show the prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the A2HS prompt');
} else {
console.log('User dismissed the A2HS prompt');
}
deferredPrompt = null;
});
});
});
@Das你能按照我在回答中的建议做以下更改并相应地测试此链接吗@Das你能按照我在回答中的建议做以下更改并相应地测试此链接吗