Dinesh
Dinesh

Reputation: 6532

Load local Html file doesn't refer the js file in UIWebView

I am working with UIWebView project and I want to load an HTML file from a project resource. It is working fine when I run from the URL, but when I view the HTML file locally, JS files are not loaded. Loading the local HTML local file doesn't refer to js files in UIWebView.

Here's my code to load the HTML file project local resource and does't refer the js file:

NSString *path = [[NSBundle mainBundle] pathForResource:@"textfile" ofType:@"txt"];
NSError *error = nil;
NSString *string = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];

NSString *path1 = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path1];
NSLog(@"%@  >>> %@",baseURL,path);

[webview loadHTMLString:string baseURL:baseURL];

This code doesn't find JS files in UIWebView, even though it loads image files from the project resource successfully.

Upvotes: 2

Views: 712

Answers (1)

Dinesh
Dinesh

Reputation: 6532

i am find the problem is js files are not automatically copy to project bundles so, you can try follow instructions like below:

go to your project target -> click tab to Bulid Phases -> expand the section copy Bundle Resources -> now find all files bin bundle resources of your project check your js files not copied,so, click + button and add js files manually on your project!

now run the project working perfectly!

like below screen shot:

enter image description here

after add js file in your project below screen shot:

enter image description here

welcome!

Upvotes: 6

Related Questions