4

I saw this question answered for Xcode 3, but Xcode 4 seems to have changed.

I am unable to figure out how to include a javascript file as a local resource for an iPhone App using UIWebView. The compiler tries to interpret the included .js files as code rather than including them in the root app bundle as a resource for reference in an html file.

In my case specifically I was trying to include a local copy of a javascript file so the UIWebView portion of the app can perform certain functions while not connected to the internet, so I need a local copy....

Anyone have this figured out for Xcode 4?

Thanks -Steve

2 Answers 2

4

Wow. Spent hours trying to figure it out, so I finally posted the question. 10 minutes later I run across a totally unrelated thread that pointed me in the right direction.

In Xcode 4 in the Project Navigator click on the top item, the project, then select your Target and click on the Build Phases tab. There is a Copy Bundle Resources in that window that will let you add the .js files you need in the local resources. Now all html references such as:

<script type="text/javascript" src="yourAwesomeCode.js"></script>

will work

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

1 Comment

I wonder why it doesn't work for you? Works great for me. ?
1

@gcamp is right, but he forgot to mention that when you call - loadHTMLString: or - loadRequest: . You must specify the baseURL to the URL of you bundle resource directory. like this

// load htmlString into web view
[webView loadHTMLString:HTMLString
        baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath] isDirectory:YES]];

```

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.