3

I would like to use external file .html to use WKWebView. Or is there a solution without external file ? All is working good on simulator, but not on device...

Here is my code :

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

I've read this topic : WKWebView not loading local files under iOS 8

I don't want to use a server. I'm using Objective-C, and I want that it works on only one view, not like the https://github.com/shazron/WKWebViewFIleUrlTest project with 2 views and button and I need to have connexion with internet in the page (read iFrame).

What have I to do ?

Community
  • 1
  • 1
Vjardel
  • 1,065
  • 1
  • 13
  • 28

1 Answers1

4

You have to copy all your web files to the app's NSTemporaryDirectory and call your index.html from there. Works fine on iOS 8.3 for me.

iquellis
  • 979
  • 1
  • 8
  • 26