You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS真机TestFlight环境下.NET MAUI WebView中PDFJs加载本地文件抛出missing_file_error异常的问题求助

iOS真机TestFlight环境下.NET MAUI WebView中PDFJs加载本地文件抛出missing_file_error异常的问题求助

大家好,我遇到了一个挺棘手的问题:我正在用.NET MAUI开发应用,打算通过WebView里的PDFJs加载应用数据目录中存储的本地PDF文件。在iOS模拟器上测试时一切正常,但把构建包上传到TestFlight后,在真实设备上测试时,PDFJs能启动,却会抛出missing_file_error异常,根本加载不了目标文件。

我已经尝试做了以下配置,不过问题依然存在:

1. MauiProgram.cs中的iOS相关WebView配置

在项目的MauiProgram.cs里添加了针对iOS和Mac Catalyst的配置代码:

#if IOS || MACCATALYST
if (handler.PlatformView is WKWebView wkWebView)
{
    wkWebView.Configuration.Preferences.SetValueForKey(Foundation.NSObject.FromObject(true), new NSString("allowFileAccessFromFileURLs"));
    wkWebView.Configuration.Preferences.SetValueForKey(Foundation.NSObject.FromObject(false), new NSString("secureContextChecksEnabled"));
    wkWebView.Configuration.Preferences.SetValueForKey(Foundation.NSObject.FromObject(true), new NSString("fileSystemAccessEnabled"));
    wkWebView.Configuration.Preferences.SetValueForKey(Foundation.NSObject.FromObject(true), new NSString("storageAPIEnabled"));
}
#endif

2. Info.plist中的网络权限配置

同时在Info.plist里配置了App Transport Security相关项:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsForMedia</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
    <key>NSAllowsLocalNetworking</key>
    <true/>
    <key>NSExceptionAllowsInsecureHTTPLoads</key>
    <true/>
</dict>

有没有朋友遇到过类似的情况?或者能给我一些排查方向或解决方案的建议?感激不尽!

备注:内容来源于stack exchange,提问作者Dev Shuters

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 07:03:10