开发者

ipad: Running a local website and storing data

开发者 https://www.devze.com 2023-02-17 05:36 出处:网络
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 i

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: [UISc开发者_开发技巧rollView 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消