【问题标题】:Titanium - Retrieving SQLite Data from previous version of iOS AppTitanium - 从以前版本的 iOS 应用程序中检索 SQLite 数据
【发布时间】:2014-06-23 03:12:31
【问题描述】:

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

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

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

谢谢, 汤姆

【问题讨论】:

    标签: ios sqlite titanium


    【解决方案1】:

    只要以前的开发人员遵守 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 有一个保存 DB 文件的特定目录,以及最新版本的 Titanium migrates any old DB's to this directory

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      相关资源
      最近更新 更多