简体   繁体   English

禁止在 iOS 上安装 PWA,只添加到主屏幕的快捷方式

[英]Suppress PWA installation on iOS, only add shortcut to Home Screen

I have a PWA that works fine on Android, but is crippled on iOS due to limitations opposed on PWAs imposed by iOS (specifically accessing live camera frames).我有一个 PWA 在 Android 上运行良好,但由于 iOS 对 PWA 施加的限制(特别是访问实时相机帧)而在 iOS 上瘫痪。 The app works fine when viewed in Safari.在 Safari 中查看时,该应用程序运行良好。 This is counter-intuitive but unfortunately the case.这是违反直觉的,但不幸的是。

Is there a way to tell iOS that it should not "install" the PWA, but instead just create a shortcut on the home screen and open it in regular Safari?有没有办法告诉 iOS 它不应该“安装”PWA,而只是在主屏幕上创建一个快捷方式并在常规 Safari 中打开它? Like any ol' website?像任何ol'网站?

Or do I need a specific index.html for iOS that does not include the manifest.json reference?或者我是否需要一个不包含 manifest.json 引用的特定于 iOS 的 index.html? The PWA is a single-page Angular application. PWA 是一个单页的 Angular 应用程序。

Answering my own question.回答我自己的问题。 I managed to solve this by programmatically removing the manifest element in the OnInit hook of the AppComponent.我设法通过以编程方式删除 AppComponent 的 OnInit 挂钩中的清单元素来解决此问题。

In index.html:在 index.html 中:

<link rel="manifest" href="manifest.json" id="manifest-link">

In the AppComponent:在 AppComponent 中:

ngOnInit() {

   // ... platform detection
   if (isiOS) {
       const element = document.getElementById('manifest-link');
       console.log(`Removing manifest element on iOS, should suppress PWA installation`);
       element.remove();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM