wkwebview运行本地html(文档中)从web进程接收到意外URL

wkwebview运行本地html(文档中)从web进程接收到意外URL,html,iframe,document,wkwebview,Html,Iframe,Document,Wkwebview,两个问题: 1.以.css.js的形式访问文件应通过完整路径,如index.html中的代码所示 2.当index.html的代码运行到“document.body.appendChild(iFrame)”时,模拟器运行到空白;xcode日志: 从web进程接收到意外的URL:'file:///Users/John_Chen/Library/Developer/CoreSimulator/Devices/20ABEC24-78BD-4577-9AA5-35CB1520F620/data/Cont

两个问题:

1.以.css.js的形式访问文件应通过完整路径,如index.html中的代码所示

2.当index.html的代码运行到“document.body.appendChild(iFrame)”时,模拟器运行到空白;xcode日志:

从web进程接收到意外的URL:'file:///Users/John_Chen/Library/Developer/CoreSimulator/Devices/20ABEC24-78BD-4577-9AA5-35CB1520F620/data/Containers/Data/Application/30A53A36-4A05-4491-A400-CEBF5F9E7D21/Documents/test/2.html' 从web进程接收到无效消息“WebPageProxy.DecidePolicyForNavigationAction”

有人能帮忙吗?TKS

iOS代码:

1.将test.zip解压缩到文档:

- (void)copyFloderToSandbox
{
   NSFileManager *fm = [NSFileManager defaultManager];
   NSString *originalPlayerPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"zip"];
   NSString *originalMovi_01Path = [[NSBundle mainBundle] pathForResource:@"movi_01" ofType:@"zip"];
   NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
   NSString *PDoc = [documentPath stringByAppendingPathComponent:@"test"];
   NSString *MDoc = [documentPath stringByAppendingPathComponent:@"movi_01"];

  if (![fm fileExistsAtPath:PDoc]) 
 {
    [SSZipArchive unzipFileAtPath:originalPlayerPath toDestination:documentPath];
 }
  if (![fm fileExistsAtPath:MDoc]) 
 {
    [SSZipArchive unzipFileAtPath:originalMovi_01Path toDestination:documentPath];
 }
}
2.WKWebView load index.html:

- (void)viewDidLoad {
[super viewDidLoad];

[self copyFloderToSandbox];

self.webView = [[WKWebView alloc]initWithFrame:self.view.bounds configuration:[self configWeb]];
_webView.navigationDelegate = self;
_webView.UIDelegate = self;
[self.view addSubview:_webView];


NSString *playerPath = [OMDBManager getLocalDataFilePathWithPathComponent:@"test"];
NSString *html = [playerPath stringByAppendingPathComponent:@"index.html"];
NSString *moviePath = [OMDBManager getLocalDataFilePathWithPathComponent:@"movi_01"];
NSString *moviParameter = [NSString stringWithFormat:@"movieroot=%@",playerPath];
NSString *playParameter = [NSString stringWithFormat:@"playerroot=%@",playerPath];
NSString *baseString = [NSString stringWithFormat:@"%@?%@&%@",html,moviParameter,playParameter];

NSURL *baseUrl = [NSURL fileURLWithPath:baseString isDirectory:YES];
NSString *htmlContent = [NSString stringWithContentsOfFile:html encoding:NSUTF8StringEncoding error:nil];
[_webView loadHTMLString:htmlContent baseURL:baseUrl];
}

- (WKWebViewConfiguration *)configWeb
{
    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration      alloc]init];
configuration.preferences = [[WKPreferences alloc]init];
configuration.preferences.minimumFontSize = 18;
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
configuration.userContentController = [[WKUserContentController alloc]init];
[configuration.userContentController addScriptMessageHandler:self name:@"readJsonFile"];
return configuration;
 }

我认为这是因为您没有使用加载文件URL:AllowingReadAccessTour:
第二个参数是html所在的目录。

我已经在gitHub上解决了它,因为WKWebview的bug。所以我用UIWebView替换了它。我认为你应该再试一次,因为UIWebView比WKWebview慢得多。Ben W是对的。这不是虫子。您需要使用loadFileURL允许对包含文件和资产的目录进行读取访问:allowingReadAccessToURL@JonphyChen我现在正面临同样的问题,你们有swift版本吗?如果是,您可以更新它。此外,我还提出了一个问题,今年晚些时候苹果阻止了应用商店中使用UIWebView的应用程序,回到这一点已不再是一个选项。确切地说,我现在面临着同样的问题,你们有swift版本吗?如果是,您可以更新它。我还提出了一个问题