Titanium-从iOS App的先前版本中检索SQLite数据 [英] Titanium - Retrieving SQLite Data from previous version of iOS App

查看:90
本文介绍了Titanium-从iOS App的先前版本中检索SQLite数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已被委托更新本机iOS应用程序,但由于我们还将其发布到其他平台上,因此我们正在使用Appcelerator的Titanium编写新版本.

I've been commissioned to update a native iOS app, but as we're also going to release it to other platforms, we're are writing the new version using Appcelerator's Titanium.

当前应用使用SQLite数据库存储用户信息. 当用户将其应用更新为新应用时,如何访问现有的SQLite数据库? 我们不想丢失任何数据.我以为我可以访问旧数据库,然后创建到新数据库的迁移.

The current app uses a SQLite database to store user information. How do I access the existing SQLite database when the user updates their app to the new one? We don't want to lose any data. I assumed I would be able to access the old database and then create a migration to a new database.

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

And what is the best way to test this? Can I install a test app with the same app id or perhaps bundle id to simulate an update?

谢谢, 汤姆

推荐答案

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

This should be possible (although it can get tricky) as long as the previous developers observed Apple rules on where the user information db was stored.

只要您具有相同的捆绑软件ID,并增加版本,就可以在测试过程中覆盖现有应用以模拟更新(确保您使用的是临时发行版),这会将用户文件保留在地方.从那里开始,当您第一次加载应用程序时,以通常的方式加载该数据库:

As long as you have the same bundle ID, and increment the version, you can overwrite the existing app during testing to simulate an update (make sure you are using an Ad-hoc distribution), this will leave the user files in place. From there, when you load your app for the first time, load that DB in the usual way:

// 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 将所有旧数据库迁移到该目录.

iOS has a specific directory where they keep DB files, and the newest version of Titanium migrates any old DB's to this directory.

这篇关于Titanium-从iOS App的先前版本中检索SQLite数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆