mardi 3 novembre 2015

how to use sqlite in iOS when i use iPhone to run the project

when i use simulator,i can find the database file in /documents .but when i use my iPhone to run the project,i can not find the database file. what time should i create the database file or use this code in my project?

NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentFolderPath = [searchPaths objectAtIndex:0];
NSString *dbFilePath = [documentFolderPath stringByAppendingString:DATABASENAME];
NSFileManager *fm = [NSFileManager defaultManager];
BOOL isExist = [fm fileExistsAtPath:dbFilePath];
if (!isExist) {
    NSString *backupDbPath = [[[NSBundle mainBundle]resourcePath]stringByAppendingString:DATABASENAME];
    [fm copyItemAtPath:backupDbPath toPath:dbFilePath error:nil];
}

Aucun commentaire:

Enregistrer un commentaire