如何通过 wkwebview 中的 html 文件中的 iframe 加载本地文件? [英] How to load local file via iframe inside html file in wkwebview?

查看:45
本文介绍了如何通过 wkwebview 中的 html 文件中的 iframe 加载本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 UIWebView 迁移到 WKWebview.虽然我可以设法迁移大部分工作流程.我被困在一个工作流程中,我无法通过 iframe 从 WKWebview 中的 html 文件加载本地文件(file://").它在 UIWebView 中运行良好.

I am migrating UIWebView to WKWebview. While I could manage to migrate most of the workflows. I am stuck at one workflow that I am not able to load the local file ("file://") via iframe from the html file in WKWebview. It was working fine in UIWebView.

如果 iframe 源是web-url"而不是本地的,它工作正常.

Also if iframe source is "web-url" and not local, it is working fine.

我在控制台上没有看到任何错误或任何消息.

I am not seeing any error or any message on the console.

我在几个线程上读到在 WKWebView 中加载 iFrame 中的本地数据被破坏,很可能是因为allowReadAccesstoURL"我为主 html 传递的设置没有正确传递给 iframe.

I read on few thread that loading local data in iFrame is broken in WKWebView, most probably because "allowReadAccesstoURL" setting which i am passing for main html is not passed to iframe correctly.

我想检查是否有办法通过 iframe 加载本地文件.

I wanted to check if there is a way to load local file via iframe.

令人失望的是,Apple 在没有提供适当替代方案的情况下破坏了该功能.

It is disappointing that Apple has broken the functionality without providing proper alternative.

推荐答案

我终于能够解决它了.问题是LoadFileUrl"的 readAccess 路径不可用.不包括作为 iframe 加载的网址.

I am finally able to resolve it. Issue was that the readAccess path for the "LoadFileUrl" was not inclusive of the url that was being loaded as iframe.

令人恼火的是,控制台日志没有提供与错误相关的任何详细信息,而且我没有看到任何网络调用,如决策策略或 iframe 加载的任何内容,这导致了混乱.

What was irritating is that console log did not give out any detail related to the error and I was not seeing any network call like decidepolicy or anything for the iframe loading, which caused the confusion.

这篇关于如何通过 wkwebview 中的 html 文件中的 iframe 加载本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆