iPhone模拟器在哪里放置数据文件? [英] Where does iPhone simulator put data files?

查看:40
本文介绍了iPhone模拟器在哪里放置数据文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用捆绑包中内置的数据库编译iPhone App,则必须使用什么路径来查找文件,以便可以打开它,如下所示:

If I compile my iPhone App with a database that has been built into the bundle what path do I have to use to find the file so that I can open it, as in:

FMDatabase* db = [FMDatabase databaseWithPath:@"/???/database.sqlite"]; 

推荐答案

在您的-(BOOL)应用程序内部:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

设置以下代码:

databaseName=@"yourfileName.sqlite";    
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
    [self checkAndCreateDatabase];

-(无效)checkAndCreateDatabase{

-(void) checkAndCreateDatabase {

BOOL success;


NSFileManager *fileManager = [NSFileManager defaultManager];

success = [fileManager fileExistsAtPath:databasePath];

if(success) return;
else
    printf("NO File found");

NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];

[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];

}

这篇关于iPhone模拟器在哪里放置数据文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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