0

I'm developing iOS App with FMDB(Database Library of using SQLite easily).

For creating and opening a database, I'm writing down the following code.

NSFileManager *manager = [NSFileManager defaultManager];
NSArray *paths = [manager URLsForDirectory:NSDocumentDirectory
                                 inDomains:NSUserDomainMask];

NSURL *documentDirs = [paths lastObject];
NSURL *writableDBPath = [documentDirs URLByAppendingPathComponent:@"test.db"];

NSString *writableDBPathString = [writableDBPath path];
NSLog(@"DB path:%@",writableDBPathString);

FMDatabase *myDatabase = [FMDatabase databaseWithPath:writableDBPathString];

[myDatabase open];

After running my Xcode Simulator, the above "NSLog" shows the following message, so I guess I can get the collect path.

2014-07-14 02:42:18.296 ninethtest[2064:a0b] DB path:/Users/myname/Library/Application Support/iPhone Simulator/7.0/Applications/D71C7BC8-8F01-486F-81FA-E1Exxxxxxx/Documents/test.db

However, the following error message appears at "NSURL *writableDBPath = [documentDirs URLByAppendingPathComponent:@"test.db"];" and "[myDatabase open];" in the above code.

Thread1:EXC_BAD_ACCESS(code=2,address=0xbf7ffffc)

Could you tell me how to solve this problem?

supermonkey
  • 631
  • 11
  • 25

1 Answers1

0

I would try doing this to get your database path.

NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *dbPath = [documentsPath stringByAppendingPathComponent:@"testDB.sqlite3"];
Jason Silberman
  • 2,471
  • 6
  • 29
  • 47
  • Thank you for your reply. I tried your method, but I got the same error.Could you tell me another method? – supermonkey Jul 14 '14 at 17:55
  • If that is not working, then I do not think that part of the code is the problem. Are you using CocoaPods? If so, I would make sure you are using the latest version. – Jason Silberman Jul 14 '14 at 17:56