ios - Angular 6 中的 window.navigator.standalone 丢失了?

标签 ios typescript angular6 progressive-web-apps navigator

Window.navigator.standalone 用于检查网站是否在 PWA 中运行,基本上,我想在网站上显示一条消息“嘿,你也可以将其安装为应用程序” ”。 但除此之外我没有找到其他方法,特别是对于 iOS Safari 而言。 请建议在这种情况下我该怎么办?

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

这就是我一直在尝试的。

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

最佳答案

这就是我检测它的方式(与我在 iOS/Safari 以及 Chrome 中提示安装 PWA 的方式相同)。

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

关于ios - Angular 6 中的 window.navigator.standalone 丢失了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55869089/

相关文章:

ios - 错误与appendPixelBuffer : withPresentationTime:

php - iPhone 和一些手机的页面响应,只占宽度的 70% 左右

javascript - 我如何在 ng2 中实现这个 promise 场景?

json - 需要将json中的子节点移至父节点

javascript - 在 Angular 6 中处理来自第三方 URL 的发布响应。无法发布错误

angular - 如何将数据从 Angular Material 对话框传递到父组件?

ios - 无法在AppStore上传应用程序,为什么会发生这种情况?

ios - 如何在特定时间后删除 SKSpriteNode

json - 使用 id 显示其他 JSON 的值

javascript - 指令不解析初始值