비전공자 개발일기

PWA Install Ready 본문

기타

PWA Install Ready

HiroDaegu 2022. 4. 7. 23:43
728x90
SMALL

PWA를 설치할 수 있음을 표시하고 사용자 지정 인앱 설치 흐름을 제공하는 방법

  1. 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;
});

https://web.dev/customize-install/?fbclid=IwAR04KRJPbp9alCuR2M_sAmn9bh65uFsAXxmCmBzGYeHHfsl0egu8-_t0Hgo 

 

자신만의 인앱 설치 경험을 제공하는 방법

beforeinstallprompt 이벤트를 사용하여 사용자에게 원활한 맞춤형 인앱 설치 환경을 제공하십시오.

web.dev

 

728x90
LIST

'기타' 카테고리의 다른 글

Pynecone  (0) 2023.01.15
IPhone Toggle Switch  (0) 2022.04.10
모바일 웹 페이지 바로가기 아이콘 등록  (0) 2022.04.06
MacBook M1에서 Homebrew 설치 + unknown command cask 문제  (0) 2022.01.22
Mac Book 유용한 단축키  (0) 2022.01.16