spaetzel
spaetzel

Reputation: 1262

Can't load JavaScript from Resource in UIWebView

I am loading a local HTML file into a UIWebView in iOS using this code

NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];

NSURL *url = [NSURL fileURLWithPath:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

[myWebView loadRequest:requestObj];

The page works fine, and the image linked within the HTML loads fine. However, the JavaScript linked off of the page is not loading.

The HTML, Image and JavaScript are all located in the same folder. (Resources/Html in my Project)

How can I get the JavaScript to load?

Upvotes: 1

Views: 4528

Answers (2)

Teja Swaroop
Teja Swaroop

Reputation: 1169

The following code works for loading an html file which has javascript files in the web view Here web is web view object and index is the html page

Web.delegate = self;

[Web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];

Upvotes: 0

spaetzel
spaetzel

Reputation: 1262

The problem was that XCode was showing me a warning:

warning: no rule to process file '$(PROJECT_DIR)/html/orientation.js' of type sourcecode.javascript for architecture i386

This answer contains the solution. Basically, I had to tell XCode to not try and build the JavaScript files, and manually drag them to the "Copy Bundle Resources" directory.

Upvotes: 7

Related Questions