NSString *databaseName = @"my.db";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
// Check if the SQL database has already been saved to the users phone, if not then copy it over
BOOL success;
// Create a FileManager object, we will use this to check the status
// of the database and to copy it over if required
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the database has already been created in the users filesystem
success = [fileManager fileExistsAtPath:databasePath];
// If the database already exists then return without doing anything
if(success) return;
// If not then proceed to copy the database from the application to the users filesystem
// Get the path to the database in the application package
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
NSLog(@"databasePathFromApp %@", databasePathFromApp);
// Copy the database from the package to the users filesystem
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
'살며 생각하며,' 카테고리의 다른 글
083 IT 교육자 간 갈등의 자그만 조각 외 (0) | 2020.02.08 |
---|---|
082 클라우드 업체 선정 외 (0) | 2020.02.08 |
080 (0) | 2020.02.07 |
079 (0) | 2020.01.21 |
078 (0) | 2020.01.20 |
최근댓글