Google Groups

Re: LocalStorage or SQLite data will no longer be backup and can be deleted


Paul Mar 16, 2012 1:12 PM
Posted in group: phonegap
I'm curious as to how this code works if Phonegap/Cordova doesn't support ARC? Not to say that it doesn't work, but I'm currently building my first app and have had to uncheck ARC to to avoid build errors. 

If someone is using MRC, where and how to apply releases in your code? 

Currently on Xcode 4.31/PhoneGap/Cordova 1.5.0/Lion 10.7.3

Thanks in advance! 



On Thursday, March 8, 2012 5:36:16 PM UTC-6, Kerri Shotts wrote:
All,

Tentative code to support NATIVE persistence of localStorage with phoneGap (at least 1.3.0, but I would imagine, it'll be the same on any version, since it doesn't use any PG constructs) is up at http://pastebin.com/5881768B

It differs from my previous solution in that it does NOT use Javascript in any form or fashion to accomplish the data copy, which means it is faster (for large datasets), and less error-prone. (And more elegant. The JS version really felt hackish.)

To use, paste into AppDelegate.m (if you are using MRC, you'll need to make a couple of changes to release the fileManager object; I'm on ARC, and so did not do so). It replaces /part/ of webViewDidStartLoad: -- I've included the remainder of that function in the pastebin, but whatever is in yours is what you should keep. Also note that if you are doing anything special with ResignActive or Terminate to merge the two functions together, as this code uses them in order to save out localStorage back to persistent storage.

It's way fresh, so take it with the grain of salt you need to; I have tested on my pre-5.1 devices, but as I have none at 5.1, I can't promise it works there yet. (Someone who is brave willing to take a go?)

If there are changes/suggestions/etc you have, feel free to make them, and if necessary, I'll adjust the paste as necessary.

On Thursday, March 8, 2012 12:44:04 PM UTC-6, Kerri Shotts wrote:
Scott,

I'm wondering the same thing... I don't see why it couldn't work (logically), but I need to get a better handle on how uiwebview is handling localStorage before I'm secure emotionally (for example: is it only ever in file__0.localstorage? The __0 implies to me that there could be __1, __2...). 

The more I think about it, however, the more I prefer the idea of a plugin/addon that would physically copy the localStorage files rather than do it in Javascript (which is slower, more likely to blow up, not suspend-safe... that is, I can't tell it to write out localStorage on a pause because of the iOS quirk that the pause handler isn't going to handle native code until after a resume...). Plus, given that localstorage is just a sqlite database with one table anyway, I'm thinking I could do my cloud/export work that way too (since I want a method of selectively working with keys)... My coding fingers are tickling now... am definitely going to play around with that and see what comes out.

On Thursday, March 8, 2012 12:24:52 PM UTC-6, ScottP wrote:
Actually, further back in this thread I adapted the process that
Gaurav Tomar ( http://gauravstomar.blogspot.com/2011/08/prepopulate-sqlite-in-phonegap.html
) uses to copy a prepopulated database over.  My modifications
basically look for the webkit database in both (pre and post iOS5.1)
locations and if it needs then copy it to the documents folder. You
can look at previous posts to see all the code changes I made to
AppDelegate.m.
Then you can use the native sqlite plugin found here:
https://github.com/davibe/Phonegap-SQLitePlugin.

This way you won't need to continually "backup" your sqlite database
since you'll be using the plugin to natively connect to the DB file
you copied to the documents folder already.

So by using your workaround, Kerri for localstorage and this
workaround for sqlite, I think we're ok moving forward...
I'll be honest I haven't looked too closely at your localstorage
workaround, but I'm guessing the code I'm using to copy the webkit DB
over could be modified into a plugin to do just as you propose for the
localstorage.


On Mar 8, 12:56 pm, Kerri Shotts <kerrisho...@gmail.com> wrote:
> Moving forward, I guess the only option is to assume that
> localStorage/sqlite is no longer persistent (even though it is supposed to
> be). Either do away with using it entirely, /OR/ implement some method that
> persists it to the documents folder. (Which is what I do with localStorage.
> Sqllite would probably be more painful...)
>
> The absolute best method to do that persistence would be to somehow copy
> the file in the cache over to the documents folder at periodic intervals
> (or when it has changed), and read it at startup to populate the cache.
> Which is sorta what I do, only in Javascript... I may perhaps work on a
> plugin that does this natively down the road. [I would assume better
> performance, less risk from that kind of proposition. Plus the native code
> could be fired on suspend -- rather than with JS, I just write it out every
> so often.]
>
> But for the current situation... *sigh* Apple was stupid and released with
> the bug, which means a lot of people are going to have their data wiped.
> Short of digging back into the filesystem or an old backup, I don't know
> any way to recover the data. :-( [[short of being jailbroken and using
> iFile..., but that's not exactly an option we can suggest!]]
>
>
>
> On Thursday, March 8, 2012 9:57:54 AM UTC-6, mikem wrote:
>
> > The big issue is that there really is nothing I can do to fix this, your
> > solution would work but there is no way to tell the people who downloaded
> > my apps to do these steps (and they probably couldn't figure out how to do
> > it either)
>
> > Is there a solution yet so this doesn't happen moving forward?
>
> > On Thursday, March 8, 2012 10:47:24 AM UTC-5, Sam wrote:
>
> >> Yes, it sucks !
>
> >> I think we should create a lot of bug report (
> >>https://bugreport.apple.com/), because it looks like Apple doesn't know
> >> the importance of the phonegap dev community (that's why they didn't fix
> >> the bug)
>
> >> On Thursday, March 8, 2012 10:16:17 AM UTC-5, mikem wrote:
>
> >>> Join the club... this bug sucks.. no real workaround as I can see to
> >>> save my users data because a fix in my app will take at least 2 weeks to
> >>> get approved and in the hands of my users.
>
> >>> I just hope the most of the heat falls on Apple not my apps!
>
> >>> On Wednesday, March 7, 2012 8:09:37 PM UTC-5, Sam wrote:
>
> >>>> They did it. Apple has released their app with that bug.
> >>>> I already got angry users that loose all their work on my app :-/
>
> On Thursday, March 8, 2012 9:57:54 AM UTC-6, mikem wrote:
>
> > The big issue is that there really is nothing I can do to fix this, your
> > solution would work but there is no way to tell the people who downloaded
> > my apps to do these steps (and they probably couldn't figure out how to do
> > it either)
>
> > Is there a solution yet so this doesn't happen moving forward?
>
> > On Thursday, March 8, 2012 10:47:24 AM UTC-5, Sam wrote:
>
> >> Yes, it sucks !
>
> >> I think we should create a lot of bug report (
> >>https://bugreport.apple.com/), because it looks like Apple doesn't know
> >> the importance of the phonegap dev community (that's why they didn't fix
> >> the bug)
>
> >> On Thursday, March 8, 2012 10:16:17 AM UTC-5, mikem wrote:
>
> >>> Join the club... this bug sucks.. no real workaround as I can see to
> >>> save my users data because a fix in my app will take at least 2 weeks to
> >>> get approved and in the hands of my users.
>
> >>> I just hope the most of the heat falls on Apple not my apps!
>
> >>> On Wednesday, March 7, 2012 8:09:37 PM UTC-5, Sam wrote:
>
> >>>> They did it. Apple has released their app with that bug.
> >>>> I already got angry users that loose all their work on my app :-/- Hide quoted text -
>
> - Show quoted text -