WKWebView 与本地文件

2023-12-20

我正在使用本地文件测试 WKWebView,该文件在模拟器中工作,但在设备中不起作用

 @interface EDPresentationViewController ()<WKNavigationDelegate,WKScriptMessageHandler>


     @property(nonatomic,strong)WKWebView *webView;

     @property(nonatomic,strong)EDPresentationController *presentationController;

 @end


@implementation EDPresentationViewController

-(void)viewDidLoad
{
    [super viewDidLoad];

    self.presentationController = [[EDPresentationController alloc]init];

    WKWebViewConfiguration *webConfiguration = [[WKWebViewConfiguration alloc]init];
    self.webView = [[WKWebView alloc]initWithFrame:self.view.frame configuration:webConfiguration];

    NSURL *presentationFolder = [self.presentationController url];
    NSURLRequest *request = [NSURLRequest requestWithURL:presentationFolder];

    [self.webView loadRequest:request];
}

我授予以下网址:

    NSURL *presentationFolder = [self.presentationController url];

没关系,因为我用 UIWebview 测试了相同的代码并且有效!

我总是遇到同样的错误:

Could not create a sandbox extension for '/'

这行不通,我想它可以在 Objective-C 中工作,就像在 swift 中一样

iOS Webkit 无法在设备上运行,但可以在 swift 模拟器上运行 https://stackoverflow.com/questions/25973319/ios-webkit-not-working-on-device-but-works-on-simulator-at-swift

任何想法将不胜感激,谢谢


更新 2-12-2014

我发现这可能是 iOS 8.1 中的一个错误,并且可能在 8.2 中修复

我已经测试过将文件移动到临时文件夹,没有收到任何错误,但 webView 是空的。

我已经使用 UIWebView 测试了相同的代码(临时文件夹)并且工作正常!

另外,我已经尝试过这个:

https://stackoverflow.com/a/26054170/426180 https://stackoverflow.com/a/26054170/426180

据我所知,这是有效的,因为 css 和 javascript 嵌入在 html 中。


Try XWebView https://github.com/XWebView/XWebView它有一个非常小的嵌入式 http 服务器。它比 GCDWebServer 小得多。 AloadFileURL:允许ReadAccessToURL https://github.com/XWebView/XWebView/blob/master/XWebView/XWebView.swift#L74方法是通过扩展添加的,因此您不知道服务器。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

WKWebView 与本地文件 的相关文章

随机推荐