EDIT - 8-15
To Refine my questions down:
1.) Can I pass data between two webviews within the same app using localStorage? If not is there a better solution?
2.) Can I use localStorage between a remote domain and local android files? If not is there a better solution?
3.) Does localStorage use cookies? Is this the same as the DOM adapter? I've seen a lot of explanations, some seem contradictory so I think I'm a bit confused about what is actually going on.
I'm creating a mobile application using phonegap and apppresser. Essentially, it is just a webview and I have two versions, and online and offline. The online version is sent to www/index.html which then redirects them to my live site. The offline version is assets/offline.html and I am going to make it appear similar to the online version so the user doesn't really know anything is inherently different other than they can no longer do online functions.
Long story short, I am trying to use lawnchair as I've only seen good comments about it and it seems pretty flexible. Let me preface this with lawnchair seems to work. I have tried the dom adapter and can successfully set and retrieve data between pages on the online version, but it does not seem to be able to be retrieved on the the offline version. The code I have used to successfully do this is below:
var store = new Lawnchair({
adapter: "dom",
name: "testing"
}, function(store) {
});
store.exists('events', function(available){
var preStr = "";
if(available){
preStr = "key is already available, ";
}else{
preStr = "key not available, ";
}
// create an object
var me = <?php echo json_encode($json_posts); ?>;
// save it
store.save(me);
// access it later... even after app restart!
store.get('events', function(me) {
$("#data").html(preStr + JSON.stringify(me));
alert(preStr + JSON.stringify(me));
});
});
and I used a slightly different variation for the offline version that doesn't save any data. So it kind of boils down to a few questions:
1.) Does lawnchair allow me to persist data on the same mobile application between domains in the webview? I'm not sure what domiain offline.html would be on, but technically index.html (the online version) is setting data on mydomain.com
2.) Is there a better technology I should be using in this scenario to persist data between html files and/or domains?
Currently, here is the best solution I have found. To re-iterate, I am using phonegap and apppresser which allows me to make my wordpress site appear as a mobile app.
In the index.html, my code looks as:
And there's the explanations:
function checkNetConnection checks for an internet connection. If it exists, I ping my wordpress site using $.get and I have JSON API plugin installed on my site. I retrieve the post data using JSON API and cache it if the app is online, as this data usually seems to persist between app restarts (this makes me believe the answers to "Can I pass data between two webviews within the same app using localStorage?" and "Can I use localStorage between a remote domain and local android files?" are no).
If the app is not online, then I just try and fetch the already cached data.
Pros:
Cons:
This is my custom solution. It will work for my company's needs. I can't promise it will work the same for others.