简体   繁体   中英

iOS App Migration - Update an old native app to Cordova, migrate data

I was wondering if anyone can give any insight into the data migration I would like to have while upgrading my app. I am updating an app that was written in native objective C, to a cordova based web-view using jquery mobile.

The existing app has "favourites" that is implemented using sqllite3.h. I was wondering if it is possible that when we post the update to the app, we can hook into this existing sqlite database, and migrate the old "favourites" into the new database, which is implemeted using localStorage.

Any insight is greatly appreciated!

We just did something similar to this. Our old native app was using CoreData. We added a check in MainViewController, in the webViewDidFinishLoad delegate method, to see if an existing database was there. If it was, then we loaded the database, converted the contents for use via localStorage and then set a flag so that it would not try to import it again. Here's a code segment that transferred it into localStorage. First we put the info we wanted to transfer into a NSMutableString, but formatted it as a javascript dictionary

    NSMutableString *dict = [NSMutableString string];
    [dict appendString:@"{"];
    [dict appendFormat:@"'notes':'%@'", notes];
    [dict appendFormat:@",'date':'%f'",seconds];
    [dict appendFormat:@",'count':'%d'",[ss.count intValue]];
    [dict appendFormat:@",'weather':'%@'",wx];
    [dict appendFormat:@",'location':'%@'",ss.event.location.name];
    [dict appendFormat:@",'latitude':'%@'",[ss.event.location.latitude stringValue]];
    [dict appendFormat:@",'longitude':'%@'",[ss.event.location.longitude stringValue]];
    [dict appendString:@"}"];

and then we passed it into the javascript like so:

    [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"importMyOldData(%@);",dict]];

This effectively calls the javascript method, and passes a dictionary of items into it. Then you can just take that and put it into local storage using Javascript, for example:

    function importMyOldData( oldData )
    {
      // if you want to inspect each item
      var notes = oldData.notes;
      localStorage.setItem( "NoteKey", notes );

      // if you want to dump the whole thing
      localStorage.setItem( "MyKey", JSON.stringify(oldData) );

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM