SQLite Database on iPhone and Simulator

I create a database and put the * .sqlite file in the source folder in Xcode. Before opening the database, I copy it to the document folder from the resources. This works fine on a simulator, but does not work on an iPhone. For some reason, the database file does not exist on the iPhone device. This is my code:

   NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseFileName];


    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL success = [fileManager fileExistsAtPath:databasePath];
    if(!success) // all the time it YES, even if I delete database
    {
        // copy database from application folder
        NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseFileName];
        BOOL fileExists = [fileManager fileExistsAtPath:databasePathFromApp];
        if (fileExists) { // It NO, for some reasons database does not exist
            [fileManager removeItemAtPath:databasePath error:nil];
            [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
        }

        [fileManager release];
    }

    return databasePath;

For some reason, this string returns NO all the time.

        BOOL fileExists = [fileManager fileExistsAtPath:databasePathFromApp];

path in database PathFromApp somthing like this

/var/alexander/xxxx-xxx-xxxx-xxx..../AppName.app/database.sqlite

Question: why the database does not exist in resources?

+3
source share
2 answers

, . iPhone , "database.sqlite" "DataBase.sqlite" - , . .

iPhone, iPhone-

+3

" " .

reset.

0

All Articles