1

I'm trying to get 2 .js files and a .css file to load in a UIWebView application on iOS via a HTML file (which is being found).. but it's not working..

The files are already copied on Copy Bundle Resources under Build Phases etc..

This is the code so far on ViewController.m

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"game1" ofType:@"html" inDirectory:nil];
    NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
    //Append javascript
    NSString *script = @"<script src>TheScript4.js</script>";
    htmlString = [htmlString stringByAppendingString:script];
    [self.webview loadHTMLString:htmlString baseURL:nil];
}

I'm running xcode6..

Any help in the right direction etc would be great, many thanks..

1 Answer 1

1

You have to specify the baseURL as your bundle path

[self.webView loadHTMLString:htmlString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];

Also, the javascript string should be like

NSString *script = @"<script src="TheScript4.js"></script>";

But you are appending this script to the end of the html file, which would be after the </html> ending tag, so it may not execute.

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.