【问题标题】:wkwebview run local html (in document) Received an unexpected URL from the web processwkwebview run local html (in document) 从 web 进程收到了一个意外的 URL
【发布时间】:2017-02-28 14:49:05
【问题描述】:

两个问题:

1.access files as .css .js 应该通过fullPath作为你看到的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.unZip 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加载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;
 }

【问题讨论】:

标签: html iframe document wkwebview


【解决方案1】:

我认为这是因为您没有使用loadFileURL:allowingReadAccessToURL:的方法 第二个参数是 html 所在的目录。

【讨论】:

  • 由于 WKWebview 的错误,我已经在 gitHub 上解决了它。所以我用 UIWebView 替换它。
  • 我认为你应该再试一次,因为 UIWebView 比 WKWebView 慢很多
  • Ben W 是对的。这不是一个错误。您需要使用 loadFileURL:allowingReadAccessToURL 允许对包含文件和资产的目录进行读取访问
  • @JonphyChen 我现在正面临同样的问题,你有 swift 版本吗?如果是的话,你能更新它吗?我也提出了问题stackoverflow.com/questions/60187859/…
  • 此外,由于 Apple 在今年晚些时候从 App Store 屏蔽了使用 UIWebView 的应用程序,因此根本不再可以选择使用 UIWebView。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-30
  • 2017-04-07
  • 2010-12-03
  • 2018-06-24
  • 2013-04-18
  • 1970-01-01
相关资源
最近更新 更多