I'm trying to use a UIWebView to display content, and jQuery to manipulate that content, but I can't get jQuery to load. Here's the code that I have setting up the UIWebView, setting the baseURL, and loading the content (an HTML file that's in the local bundle):
UIWebView *view = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSData *htmlData = [[NSData alloc] initWithContentsOfURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]]];
NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
[view loadHTMLString:htmlString baseURL:baseURL];
The content loads just fine, and I've confirmed that the baseURL is correct by adding an image to the bundle and referencing it in the HTML, and it works. Using the same HTML in Safari on my Macbook jQuery is loading just fine, too, and working as expected.
I've tried both using the compressed jquery-1.3.2.min.js and the development jquery-1.3.2.js, and no dice for either.
Any ideas?
Gah! EBCAK!
Turns out when I copied the jquery javascript source into the project, it was copied into the target's "Compile Sources," which of course threw errors. I deleted it from "Compile Sources" but didn't add it back to "Copy Bundle Resources."
/me slaps forehead repeatedly.
Have you tried copying both the .html and .js files to the app's documents folder, and pointing the UIWebView to that local folder?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With