2

Window.navigator.standalone is for checking that the website is running in PWA or not, basically, I want to show a message on the website "hey, you can install it as an app too". but I found no way other than this, especially for iOS Safari. please suggest in this case what do I do?

const isInWebAppiOS = window.navigator.standalone;
const isInWebAppChrome = window.matchMedia('(display-mode: standalone)')
      .matches;
alert(
      'isInWebAppiOS: ' +
        isInWebAppiOS +
        'isInWebAppChrome: ' +
        isInWebAppChrome
    );

this is what I have been trying.

shareClick() {
    let newVariable: any;
    newVariable = window.navigator;
    debugger;
    const isInWebAppiOS = JSON.stringify(window.navigator);
    const isInWebAppChrome = window.matchMedia('(display-mode: standalone)')
      .matches;
    alert(
      'isInWebAppiOS: ' +
        isInWebAppiOS +
        'isInWebAppChrome: ' +
        isInWebAppChrome
    );
    if (newVariable && newVariable.share) {
      newVariable
        .share({
          title: this.title,
          text: this.description,
          url: window.location.href
        })
        .then(() => console.log('Successful share'))
        .catch(error => console.log('Error sharing', error));
    } else {
      this.dialogService.shareWithData(window.location.href);
    }
  }
Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42
anoop namdev
  • 21
  • 1
  • 3

1 Answers1

2

This is how I detect it (same thing I prompt for PWA install in iOS/Safari as well as Chrome in general).

this.isInStandaloneMode = ('standalone' in window.navigator) && (window.navigator['standalone']);

Matt
  • 4,405
  • 1
  • 17
  • 9