Marco Melluso
Marco Melluso

Reputation: 1

Load local database in UIWebView

I'm creating a little app which uses a UIWebView to load a local html. this html page has a dynamic form that load data storaged in a database. the app have to work always offline.

the question is, how can I load, for example with AJAX calls, this data from my UIWebView? I tried HTML 5 SQL local storage, but I got just to create a db. is there one way to populate that db with the data inside my db?

Upvotes: 0

Views: 549

Answers (1)

SnowboardBruin
SnowboardBruin

Reputation: 3685

Are you looking for code to call for the stored webpage, or are you looking for HTML to call for the stored DB?

Assuming the former:

Create the HTML file and keep it in a folder (let's call it "index.html" and the folder "code" for this example) and drag it into your Supporting Files folder in xcode. Click the "Copy items..." checkbox and "create folder references..."

Then use this code in your ViewDidLoad:

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"index" 
                                                     ofType:@"html"
                                                inDirectory:@"code"];
NSURL* fileURL = [NSURL fileURLWithPath:filePath];
NSURLRequest* request = [NSURLRequest requestWithURL:fileURL];
[webView loadRequest:request];

Upvotes: 1

Related Questions