2011-03-15 15 views
1

我試圖在沒有網絡連接的ipad上運行web表單。到目前爲止,我已經成功地通過使用一個需要html文件並在瀏覽器中顯示它的應用程序將表單加載到safari中。ipad:運行本地網站和存儲數據

但是,html 5的數據存儲sql組件似乎不起作用。我從html5rocks.com複製了代碼 http://playground.html5rocks.com/#async_transactions 似乎在我的應用程序中無處不在。

所以我的應用程序是非常簡單,它只是加載一個網頁瀏覽器......這裏的相關代碼

- (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]; 

回答

3

的問題是,Xcode中試圖編譯我js文件。 爲你付出!

反正看在Xcode中的項目列表右側,當你有一個項目打開

認準目標,它有一個弓和箭的目標的照片,或像紅色和白色飛鏢。打開那個,看編譯的資源。從那裏移動任何js文件到拷貝捆綁資源。

Bam!它現在應該按預期工作。