How to write the following directories into Documents?
The actual requirement is to load a website locally. I did an experiment myself. If I put it into the Documents
folder, read the index.html
file in it. Can be loaded normally. So I want to write the website files to the Documents
file directory. But I can't figure out how to write a directory into it. I hope you can give me some ideas.
滿天的星座2017-05-17 10:08:36
If you want to create a folder directly in the project,
select Create folder references when dragging it into the project, and then you will see that the folder you dragged into the project is blue.
The structure in this folder will be saved, and you can directly use relative paths to obtain it when importing js and css.
Load your html:
//swift
let path = Bundle.main.path(forResource: "YourHTMLName", ofType: "html", inDirectory: "YourFolderName")
let url = NSURL.init(string: path!)
let request = NSURLRequest.init(url: url! as URL)
webView.loadRequest(request as URLRequest)
// OC
NSURL *html = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"YourHTMLName" ofType:@"html" inDirectory:@"YourFolderName"]];
NSURLRequest *request = [NSURLRequest requestWithURL:html];
[self.webView loadRequest:request];