2

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.

1 Answer 1

6

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.