IPhone SDK: WebView, how to specify a local URL?

I have HTML files that I want to download locally. I have included the files in the resource folder in Xcode. I'm not sure which syntax loads them.

This is the code that I use to connect to Google.

NSString * urlAddress=@ "http\\someurl"; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webHelpView loadRequest:requestObj]; 

Can someone provide an example where the HTML file is loaded locally.

Thanks in advance.

+4
source share
3 answers

This is the only code that worked for me.

 NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"SettingsHelp.html"]; NSURL *url = [NSURL fileURLWithPath:path isDirectory:NO]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; 

Thank you all for your help.

+5
source

Can't you just do

 NSURL *url = [NSURL URLWithString:@"file:///path/to/file"]; 

?

+1
source

Of course, here is what code from the application loads the locally stored html page into the web view:

 - (void) viewDidLoad { // Load the content into the view NSString* path = [NSString stringWithFormat: @"%@/index.html", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0]]; [webView_ loadRequest: [NSURLRequest requestWithURL: [NSURL fileURLWithPath: path]]]; } 
0
source

Source: https://habr.com/ru/post/1299506/


All Articles