WKWebView与本地文件 [英] WKWebView with local file

查看:101
本文介绍了WKWebView与本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm testing the WKWebView with local file, which is working in the simulator but it is not working in the device

 @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];
}

我从以下位置授予了该网址:

I grant the url from:

    NSURL *presentationFolder = [self.presentationController url];

可以,因为我使用UIWebview测试了相同的代码并且可以正常工作!

is ok, because I tested the same code with a UIWebview and works!

我总是遇到相同的错误:

I always get the same error:

Could not create a sandbox extension for '/'

这是行不通的,我想它可以像在Swift中一样在Objective-C中行事

This wasn't work, I guess it would work in Objective-C as in swift

无法在iOS Webkit上运行设备,但可以在模拟器上快速运行

任何想法都会感激,谢谢

Any idea will be appreciated, thanks

更新2-12-2014

Update 2-12-2014

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

I've discovered this could be a bug in iOS 8.1 and it may be fixed in 8.2

https://devforums.apple.com/thread/247777?start = 25& tstart = 0

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

I've tested moving the files to the temporary folder and I didn't get any error but the webView is just empty.

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

I've tested the same code (temporary folder) with a UIWebView and works fine!

此外,我已经尝试过:

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

我发现这是可行的,因为CSS和javascript嵌入在html中.

As I could find out, this works because the css and the javascript is embebed in the html.

推荐答案

尝试 XWebView ,它有一个非常小型嵌入式HTTP服务器.它比GCDWebServer小得多. loadFileURL:allowingReadAccessToURL 方法是通过扩展名添加的,因此您不知道服务器.

Try XWebView which has a very tiny embedded http server. It's much smaller than the GCDWebServer. A loadFileURL:allowingReadAccessToURL method is added through extension, so you are not aware of the server.

这篇关于WKWebView与本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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