【发布时间】:2015-01-29 18:45:50
【问题描述】:
我正在使用本地文件测试 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 not working on device, but works on simulator at swift
任何想法将不胜感激,谢谢
2014 年 2 月 12 日更新
我发现这可能是 iOS 8.1 中的一个错误,它可能会在 8.2 中修复
https://devforums.apple.com/thread/247777?start=25&tstart=0
我已经测试过将文件移动到临时文件夹,但没有收到任何错误,但 webView 只是空的。
我已经用 UIWebView 测试了相同的代码(临时文件夹)并且工作正常!
另外,我试过这个:
https://stackoverflow.com/a/26054170/426180
据我所知,这是因为 css 和 javascript 嵌入在 html 中。
【问题讨论】:
-
我不认为这是一个错误,它在测试版中工作并停止在最终的 8.0 版本中工作,苹果知道它还没有修复它
-
嗯,这比错误更糟糕:),尽管它可能在 beta 版中工作,因为嵌入了 css 和 javascript 代码。感谢您的评论
-
顺便说一句,8.2 beta 好像也不能加载本地文件
-
正如您在发布的最后一个链接中看到的那样,有些人正在使用 GCDWebServer (github.com/swisspol/GCDWebServer) 来加载文件
-
是的,我看到了,但我认为这是一个很大的解决方法。
标签: ios objective-c wkwebview