Home > Software engineering >  How to check whether my React PWA is already installed on the device(Desktop/Android/IOS) to customi
How to check whether my React PWA is already installed on the device(Desktop/Android/IOS) to customi

Time:08-03

I want to add a Terms and Conditions page on my app's launch, but only when the app is installed the first time and the Agree button is not clicked. How Do I Check if the app is already installed on the device?

CodePudding user response:

When first installed, your service worker will trigger the install event https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/install_event

Once installed, your service worker will activate https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/activate_event

If you get the activate event without the install event, you can determine it was already installed.

However, from your description, the main requirement you are expressing seem to be to skip showing the terms and conditions once the user has agreed to them once. You could simply save the agreement state to something as simple as localStorage https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage.

I would further suggest you save the term and condition version as a state in case you need to update them in the future. Your updated app would look for an accepted version and show the new terms if needed.

  • Related