代码之家  ›  专栏  ›  技术社区  ›  Vjardel

WKWebView无法为“/”创建沙盒扩展

  •  3
  • Vjardel  · 技术社区  · 11 年前

    我想使用外部文件.html来使用WKWebView。或者有没有没有外部文件的解决方案?在模拟器上一切都很好,但在设备上却不行。。。

    这是我的代码:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"myHTML" ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    WKWebViewConfiguration *theConfiguration =
    [[WKWebViewConfiguration alloc] init];
    [theConfiguration.userContentController
     addScriptMessageHandler:self name:@"interOp"];
    _webView = [[WKWebView alloc] initWithFrame:self.view.frame
                                     configuration:theConfiguration];
    [_webView loadRequest:request];
    [self.view addSubview:_webView];
    

    我读过这个主题: WKWebView not loading local files under iOS 8

    我不想使用服务器。我使用的是Objective-C,我希望它只在一个视图上工作,而不是像 https://github.com/shazron/WKWebViewFIleUrlTest 项目有2个视图和按钮,我需要在页面中连接互联网(阅读iFrame)。

    我该怎么办?

    1 回复  |  直到 9 年前
        1
  •  4
  •   iquellis    11 年前

    您必须将所有web文件复制到应用程序的NSTemporaryDirectory中,然后从那里调用index.html。对我来说,在iOS 8.3上运行良好。