2017-01-10 89 views
0

我正在使用WKWebview加載本地html文件。該文件夾位於tmp目錄中。 js和css的相對路徑在嵌套文件夾中。 (../css/font.css,../js/player.js),其中父文件夾中的html。網址不在wkwebview從本地存儲加載WKWebview未加載本地HTML/CSSS文件

Root folder name - HTMLFiles 
Root HTML Path - HTMLFiles/HTML/index.html 
CSS path - HTMLFiles/design/CSS/font.css 
JS path - HTMLFiles/JSPath/JS/player.js 

> > Below I am trying to read from temp directory and loading into 
>  > wkwebview urlToLoad = [NSString 
>  > stringWithFormat:@"file://%@/HTMLFiles/HTML/index.html", 
>  > NSTemporaryDirectory()];; SEL sel = 
>  > NSSelectorFromString(@"loadFileURL:allowingReadAccessToURL:"); if 
>  > ([self.webView respondsToSelector:sel] && 
>  > self.useLoadFileURLreadAccessURL) { NSString* directory = 
>  > [self.urlToLoad stringByDeletingLastPathComponent]; 
>  >   ((id (*)(id, SEL, id, id))objc_msgSend)(self.webView, sel, [NSURL URLWithString:self.urlToLoad], [NSURL 
>  > URLWithString:directory]); 
>  >   [_webView loadFileURL:[NSURL URLWithString:self.urlToLoad] allowingReadAccessToURL:[NSURL 
> URLWithString:directory]]; 
>  >  } else { 
>  >   // load the passed in URL 
>  >   [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlToLoad]]]; } 
+0

如果在打印出urlToLoad字符串時該怎麼辦? –

+0

你能通過編輯來澄清你的問題嗎? –

回答