I'm trying to run a web form on an ipad that has no web connection. So far i've successfully been able to load the form into safari through the use of an app that takes a html file and displays it in a browser.
However, the data store sql component of html 5 just doesn't seem to work. I copied the code from html5rocks.com
http://playground.html5rocks.com/#async_transactions
Seems to work everywhere but in my application.
So my app is very simple, it just loads a web browser... here's the relevant code
- (void)viewDidLoad {
// Example 1, loading the content from a URLNSURL
//NSURL *url = [NSURL URLWithString:#"http://dblog.com.au"];
//NSURLRequest *request = [NSURLRequest requestWithURL:url];
//[webView loadRequest:request];
NSString *webPage = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
NSData *webData = [NSData dataWithContentsOfFile:webPage];
NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:#"/" withString:#"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
// NSString *HTMLData = #"
// <h1>Hello this is a test</h1>
// <img src="sample.jpg" alt="" width="100" height="100" />";
// [webView loadHTMLString:HTMLData baseURL:[NSURL URLWithString: [NSString stringWithFormat:#"file:/%#//",imagePath]]];
//[webView loadHTMLString:webPage baseURL:[NSURL URLWithString: [NSString stringWithFormat:#"file:/%#//",imagePath]]];
//[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:webPage isDirectory:NO]]];
NSString *baseStr = [NSString stringWithFormat:#"file:/%#//",imagePath];
NSURL *baseURL = [NSURL URLWithString: baseStr];
NSLog(#"%#",baseStr);
//webView.scalesPageToFit = YES;
//webView.multipleTouchEnabled = YES;
/*for (id subview in webView.subviews){
if([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
}*/
[webView loadData:webData MIMEType:#"text/html" textEncodingName:#"UTF-8" baseURL:baseURL];
//[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.cyberdesignworks.com.au/clients/ideatoaction"]]];
//[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Test" ofType:#"svg"]isDirectory:NO]]];
[super viewDidLoad];
The problem was that Xcode tries to compile my js files.
DAMN YOU APPLE!
anyway look on the right in the list of items in xcode when you have a project open
look for targets, it has a picture of a bow and arrow target, or like a red and white dart board. open that up, look at compiled resources. Move any js files from there to the copy bundled resources.
Bam! it should all work as intended now.
Related
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
NSURL *baseURL = [NSURL fileURLWithPath:htmlFile];
NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile
encoding:NSUTF8StringEncoding
error:nil];
myWebView = [[UIWebView alloc] init];
[myWebView loadHTMLString:htmlString baseURL:baseURL];
My code is like this. In index.html, I have
<img src="dog.gif"/>
<h1>index.html loaded</h1>
Both the index.html and dog.gif are stored in the PROJECT_ROOT/Resources/.
But my app works OK on the simulator, but fails to load dog.gif on my iPad. The text is showed on both. I cleaned the project, but that didn't work.
Attempting to load an html file into webview that has images that link to other pages in the supporting files folder. The main html file loads but the images and link do not work. Any suggestion on how to solve this problem? I'm referencing my img file as img src="$#%.png".
- (void)viewDidLoad {
[super viewDidLoad];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"iphone"
ofType:#"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile
encoding:NSUTF8StringEncoding error:nil];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[myWebView loadHTMLString:htmlString baseURL:baseURL];
[myWebView loadHTMLString:htmlString baseURL:[[NSBundle mainBundle]
bundleURL]];
[myWebView loadHTMLString:htmlString baseURL:nil];
}
Use this code to load html file in UIWebView :
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"iphone" ofType:#"html"] isDirectory:NO]]];
I have a super simple webpage that I just want to load a single local file. The file is /Resources/About.html
Here is my code:
NSString *urlPath = [[NSBundle mainBundle] URLForResource:#"About" withExtension:#"html"];
NSURL *url = [NSURL fileURLWithPath:urlPath];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
What's wrong?
The method URLForResource:withExtension returns an NSURL, not an NSString. You can use the result of that directly in your request.
NSURL *URL = [[NSBundle mainBundle] URLForResource:#"About" withExtension:#"html"];
[webView loadRequest:[NSURLRequest requestWithURL:URL]];
NSString * urlPath = [[NSBundle mainBundle] pathForResource:#"About" ofType:#"html"];
NSString *content = [NSString urlPath encoding:NSUTF8StringEncoding error:nil];
[webView content baseURL:[NSURL urlPath]];
I bet URLForResource is returning nil (Can you confirm that it is not?). It will not perform a recursive search, and will fail if your "Resources" folder is an actual folder (blue in XCode) as opposed to a group (yellow in Xcode). Try using the main bundle's resourceURL and appending your path to the end of it.
I have the following code to load a local html file in an iOS app.
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];
The above works, however I need to load an anchor as this is a single page web app embedded in a UIWebview.
Basically how do I load index.html#settings for instance instead of just index.html.
This worked for me.
NSString *basePath = [[NSBundle mainBundle] pathForResource:#"page.html" ofType:nil];
NSURL *baseURL = [NSURL fileURLWithPath:basePath];
NSURL *fullURL = [NSURL URLWithString:#"#anchor1" relativeToURL:baseURL];
// Now do whatever with this fullURL
The # is converted to %23 in [NSURL fileURLWithPath:basePath], but URLWithString:(NSString *)URLString relativeToURL:(NSURL *)baseURL; not.
I have an iPad UIWebView which has to display some rtfd.zip files. I try to do it like this:
-(void) viewWillAppear:(BOOL)animated {
[self loadFile:string];
}
- (void)loadFile:(NSString*)file
{
NSString* resourcePath = [[NSBundle mainBundle] bundlePath];
NSString* sourceFilePath = [resourcePath stringByAppendingPathComponent:file];
NSURL* url = [NSURL fileURLWithPath:sourceFilePath isDirectory:NO];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
[resourcePath release];
}
But I only get a blank page. The outlets are definitely connected properly - the UIWebView can load google main page.
What am I doing wrong?
Thanks in advance!
Try to use this, I got output by using this,
- (void)loadFile:(NSString*)file {
UIWebView *webview=[[UIWebView alloc] init];
NSString *FullstrURL=[[NSBundle mainBundle] pathForResource:file
ofType:#"html" ];
NSLog(#"HTML String = %#",FullstrURL);
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:FullstrURL]]];
}