开发者

How can I find the database path for iPhone/iPad device or iPhone/iPad simulator?

开发者 https://www.devze.com 2023-03-25 09:11 出处:网络
I am using a local开发者_JS百科 sqlite3 database and I need to find out the path to it so I can open a connection. Are the paths for device/simulator different? How can I find them?It depends on where

I am using a local开发者_JS百科 sqlite3 database and I need to find out the path to it so I can open a connection. Are the paths for device/simulator different? How can I find them?


It depends on where you create your Database in your iphone application. The way I have created is under Documents folder of the sandbox and the path are always same for both of them.

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

So the path of the database is /Library/Application Support/iPhone Simulator/4.2/Applications//Documents/mainDB.sqlite


To open a database that is in your bundle, you can do:

sqlite3 *_database;

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"yourDbName.extension"];

sqlite3_open_v2([path UTF8String], &_database, SQLITE_OPEN_READONLY, NULL);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号