gpt4 book ai didi

ios - 如何修复 iOS 设备(UniWebView 3,Unity)上的 WKWebView 在 .html 中加载图像?

转载 作者:行者123 更新时间:2023-11-28 23:29:24 25 4
gpt4 key购买 nike

我使用适用于 Unity 的 UniWebView 3 插件来显示本地 .html 文件。此插件使用 WKWebView,它不会在 iOS 设备上以 .html 加载本地镜像。但是 .css 和 .js 文件成功加载(在标题中)。在 Unity 编辑器中图像正确显示 (macOS)。

图片标签是:

<img src="highlights-14.png" alt="image description" />

highlights-14.png 与 index.html 在同一文件夹中。

我也尝试过这样的标签:

<img src=«/highlights-14.png" alt="image description" />
<img src=«./highlights-14.png" alt="image description" />
<img src=«../highlights-14.png" alt="image description" />
// With moving image into associated folder
<img src=«images/highlights-14.png" alt="image description" />
<img src=«/images/highlights-14.png" alt="image description" />
<img src=«./images/highlights-14.png" alt="image description" />

我尝试在 Load 方法中使用 readAccessURL(loadFileURL:allowingReadAccessToURL: in WKWebView)。如果我有一个 URL(站点路径)如下所示:

file:///var/containers/Bundle/Application/.../Data/Raw/Products/Research.html

然后我将有下一个 readAccessURL:

file:///var/containers/Bundle/Application/.../Data/Raw/Products/

我也试过这个字符串用于 readAcessURL:

file:///var/containers/Bundle/Application/.../Data/Raw/Products

还有这个:

file:///var/containers/Bundle/Application/.../Data/Raw/

还有一些……

我尝试将具有 «YES» 值的 «Allow Arbitrary Loads in Web Content» 键添加到 info.plist(在 App Transport Security Settings 下)。

WKWebView 仍然没有加载任何图像。感谢您提出任何建议。

最佳答案

如果您在 iOS 上的 UniWebView 中指定了正确的路径,本地镜像应该可以正常工作。

假设 StreamingAssets 文件夹中有一个页面“index.html”,并且“image.jpg”文件位于该 HTML 文件旁边。

流媒体 Assets -- 索引.html -- 图片.jpg

然后您可以在页面中加载图像:

<img src="image.jpg" alt="A demo image" />

在 C# 中

var url = UniWebViewHelper.StreamingAssetURLForPath("page3.html");
webView.Load(url);

如果您的图像位于父文件夹中,您可能需要在 Load 方法中指定正确的“readAccessURL”参数。可以查看Load方法的文档here .

关于ios - 如何修复 iOS 设备(UniWebView 3,Unity)上的 WKWebView 在 .html 中加载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57327087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com