기타
PWA Install Ready
HiroDaegu
2022. 4. 7. 23:43
728x90
SMALL
PWA를 설치할 수 있음을 표시하고 사용자 지정 인앱 설치 흐름을 제공하는 방법
- beforeinstallprompt 이벤트 실행
// Initialize deferredPrompt for use later to show browser install prompt.
let deferredPrompt;
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent the mini-infobar from appearing on mobile
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
// Update UI notify the user they can install the PWA
showInstallPromotion();
// Optionally, send analytics event that PWA install promo was shown.
console.log(`'beforeinstallprompt' event was fired.`);
});
2. 인앱 설치 흐름
buttonInstall.addEventListener('click', async () => {
// Hide the app provided install promotion
hideInstallPromotion();
// Show the install prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
const { outcome } = await deferredPrompt.userChoice;
// Optionally, send analytics event with outcome of user choice
console.log(`User response to the install prompt: ${outcome}`);
// We've used the prompt, and can't use it again, throw it away
deferredPrompt = null;
});
자신만의 인앱 설치 경험을 제공하는 방법
beforeinstallprompt 이벤트를 사용하여 사용자에게 원활한 맞춤형 인앱 설치 환경을 제공하십시오.
web.dev
728x90
LIST