我维护一个SQLite数据库在我的iPhone应用程序,所以,我想知道如何可以坚持一个单一的版本和更新。iPhone的SQLite数据库路径问题
其表示,如果要进行更新的分贝ü应该将它复制到文件夹
在我的iPhone模拟器一样,每次文件夹改变我打开应用程序
如果其复制并修改被做了..如何应用程序反映在我的应用程序包 db的更新,所以当应用程序再次启动时,应用程序将数据库再次从我的包复制到文档文件夹,以便能够对其进行更改..
我的问题是,有时我会进行更改并再次加载应用程序以找到在变化消失了!
所有我做了什么:
- 创建使用某种路径上和资源的终端在Xcode文件夹右键单击添加现有文件
- 我这个每次做我加载应用程序的数据库:
-(void)DBinit
{
// Setup some globals
databaseName = @"articlesdb.sql";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [[documentsDir stringByAppendingPathComponent:databaseName] copy];
NSLog(databasePath);
// Execute the "checkAndCreateDatabase" function
[self checkAndCreateDatabase];
}
-(void)checkAndCreateDatabase
{
// Check if the SQL database has already been saved to the users phone, if not then copy it over
BOOL success;
// Create a FileManager object, we will use this to check the status
// of the database and to copy it over if required
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the database has already been created in the users filesystem
success = [fileManager fileExistsAtPath:databasePath];
// If the database already exists then return without doing anything
if(success)
{
[fileManager removeItemAtPath:databasePath error:nil];
return;
}
// If not then proceed to copy the database from the application to the users filesystem
// Get the path to the database in the application package
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
// Copy the database from the package to the users filesystem
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
fileManager release];
}
感谢您的帮助和时间 我想要做的是在用户对文档文件夹中的数据库进行更改之后。 我希望将它复制到数据库中的数据库中。 – 2009-11-10 10:02:58
或自动发生 – 2009-11-10 10:03:59
Bundle始终为只读。没有东西可以被复制回来。这就是为什么你必须将数据库复制到Downloads文件夹,否则数据库是只读的。 – mahboudz 2009-11-10 11:41:20