如何在 index.html 中添加内容安全策略

How to add Content Security Policy in index.html

我在 Ionic 中开发应用程序,当我在 iOS 设备中 运行 这个应用程序时,它会在闪屏上卡住一段时间,然后 load.I 检查控制台,它会显示该设备ready 在 95245 ms 后被触发。这意味着设备准备就绪时间过长。

我搜索了这个问题并找到了类似的问题 并且接受的解决方案如下所示:


如路易所言

I added Thanks for your response @baviskarmitesh. But I had to add gap to the content security policy and now it seems to work.

I added data: gap: https://ssl.gstatic.com 'unsafe-eval'after default-src * into my content security policy in my index.html file, like this:

meta http-equiv="Content-Security-Policy" content=" default-src * data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; connect-src 'self' 'unsafe-inline' 'unsafe-eval' blob: ws: *; "> And now deviceready fires quickly with all my plugins.

现在我试图在我的 index.html 中为 Content-Security-Policy 传递这个 meta 标签,但是每当我使用这个命令构建我的 iOS 应用程序时。

ionic cordova build ios

Content-Security-Policy 元标记已自动从我的 index.html 中删除。那么如何在我的 index.html 中添加这个 Content-Security-Policy?还有其他办法吗?

确保您正在对 src 文件夹中的 index.html 文件进行更改。

当您 运行 ionic cordova build ios 时,它会生成包含 src 内容的 www 文件夹,Cordova 使用 www 文件夹内容构建应用程序。