iOS 应用程序迁移 - 将旧的本机应用程序更新到 Cordova,迁移数据
iOS App Migration - Update an old native app to Cordova, migrate data
我想知道是否有人可以深入了解我在升级我的应用程序时希望进行的数据迁移。我正在使用 jquery mobile.
将使用本机 objective C 编写的应用程序更新为基于 cordova 的网络视图
现有应用有 "favourites" 是使用 sqllite3.h 实现的。我想知道是否有可能当我们 post 更新应用程序时,我们可以连接到这个现有的 sqlite 数据库,并将旧的 "favourites" 迁移到新数据库中,这是使用 localStorage 实现的。
非常感谢任何见解!
我们刚刚做了类似的事情。我们的旧本机应用程序使用的是 CoreData。我们在 MainViewController 的 webViewDidFinishLoad 委托方法中添加了一个检查,以查看是否存在现有数据库。如果是,那么我们加载数据库,转换内容以供通过 localStorage 使用,然后设置一个标志,这样它就不会尝试再次导入它。这是将其传输到 localStorage 的代码段。首先,我们将要传输的信息放入 NSMutableString,但将其格式化为 javascript 字典
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:@"}"];
然后我们像这样将它传递给 javascript:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"importMyOldData(%@);",dict]];
这有效地调用了 javascript 方法,并将项目字典传递给它。然后你可以使用 Javascript 将它放入本地存储,例如:
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) );
}
我想知道是否有人可以深入了解我在升级我的应用程序时希望进行的数据迁移。我正在使用 jquery mobile.
将使用本机 objective C 编写的应用程序更新为基于 cordova 的网络视图现有应用有 "favourites" 是使用 sqllite3.h 实现的。我想知道是否有可能当我们 post 更新应用程序时,我们可以连接到这个现有的 sqlite 数据库,并将旧的 "favourites" 迁移到新数据库中,这是使用 localStorage 实现的。
非常感谢任何见解!
我们刚刚做了类似的事情。我们的旧本机应用程序使用的是 CoreData。我们在 MainViewController 的 webViewDidFinishLoad 委托方法中添加了一个检查,以查看是否存在现有数据库。如果是,那么我们加载数据库,转换内容以供通过 localStorage 使用,然后设置一个标志,这样它就不会尝试再次导入它。这是将其传输到 localStorage 的代码段。首先,我们将要传输的信息放入 NSMutableString,但将其格式化为 javascript 字典
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:@"}"];
然后我们像这样将它传递给 javascript:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"importMyOldData(%@);",dict]];
这有效地调用了 javascript 方法,并将项目字典传递给它。然后你可以使用 Javascript 将它放入本地存储,例如:
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) );
}