私の意見では、imagePathをSQLiteに保存し、画像をドキュメントディレクトリに保存します。私も同じです。これはあなたを助けるかもしれません。
-(void)saveDataToDatabase:(NSString *)fileNameToSave
{
NSString *docsDir;
NSArray *dirPaths;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
sqlite3_stmt *statement;
NSString *databasePath = [[NSString alloc]
initWithString: [docsDir stringByAppendingPathComponent:
@"scanner.db"]];
NSLog(@"%@",databasePath);
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &databaseHandle) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat: @"Insert into IMAGEINFO (NAME,IMAGEPATH) values ('%@','%@')",@"imageFirst",fileNameToSave];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(databaseHandle, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"database"];
}
else
{
}
}
}
-(void)saveImage:(NSString *)fileName:(UIImage *)imageToSave
{
NSError *error;
NSString *fileNaToSave = [NSString stringWithFormat:@"Documents/%@.png",fileName];
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:fileNaToSave];
// Write image to PNG
[UIImagePNGRepresentation(imageToSave) writeToFile:pngPath atomically:YES];
// Let's check to see if files were successfully written...
// You can try this when debugging on-device
// Create file manager
NSFileManager *fileMgr = [NSFileManager defaultManager];
// Point to Document directory
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// Write out the contents of home directory to console
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
}