gpt4 book ai didi

ios - Titanium - 从以前版本的 iOS 应用程序中检索 SQLite 数据

转载 作者:行者123 更新时间:2023-11-29 10:43:07 24 4
gpt4 key购买 nike

我受委托(delegate)更新原生 iOS 应用程序,但由于我们还将其发布到其他平台,我们正在使用 Appcelerator 的 Titanium 编写新版本。

当前应用使用SQLite数据库存储用户信息。当用户将他们的应用程序更新到新数据库时,我如何访问现有的 SQLite 数据库?我们不想丢失任何数据。我假设我将能够访问旧数据库,然后创建到新数据库的迁移。

测试这个的最佳方法是什么?我可以安装具有相同应用 ID 或 bundle ID 的测试应用来模拟更新吗?

谢谢,汤姆

最佳答案

只要以前的开发人员遵守 Apple 关于用户信息数据库存储位置的规则,这应该是可能的(尽管它可能会变得棘手)。

只要您拥有相同的包 ID 并增加版本,您就可以在测试期间覆盖现有应用以模拟更新(确保您使用的是 Ad-hoc 分发),这会将用户文件保留在地方。从那里,当您第一次加载您的应用程序时,以通常的方式加载该数据库:

// Set a property so you do this only one time when they first update
if(Ti.App.Properties.getBool('isDatabaseMigrated', false)) {
// See if the DB file exists (this may be a fresh install not an update)
var dbfile = Ti.Filesystem.getFile(Ti.Filesystem.applicationSupportDirectory+'/database', 'nameOfDB.sql');
if(dbfile.exists()) {
// Open the DB
var db = Ti.Database.open('nameOfDB');
.... Now do your thing ....
db.close();
}
// Set flag so we only check this once
Ti.App.Properties.setBool('isDatabaseMigrated', true);
}

iOS 有一个保存数据库文件的特定目录,以及最新版本的 Titanium migrates any old DB's to this directory .

关于ios - Titanium - 从以前版本的 iOS 应用程序中检索 SQLite 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23495832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com