ドキュメント フォルダ内の 1 つのファイルを確認したい。このファイルがドキュメント フォルダに存在しない場合は、メイン バンドルからドキュメント フォルダにコピーします。私はこのコードとこのファイルをコピーするように書いていますが、ここで私の問題.....!!!! 私のファイルは .sqlite ファイル (データベース ファイル) であり、ドキュメント フォルダーにコピーすると、データが自分自身にありません!!!! どうして???このファイルがメインバンドルにあるときは、それ自体にデータがあります。
これは私のコードですが、なぜ機能しないのかわかりません!!!!
#define DataName @"mydatabase.sqlite"
- (void)viewDidLoad
{
[self CopyDatabase];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (NSString*)DatabasePath
{
NSArray *Paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *DocumentDir = [Paths objectAtIndex:0];
//NSLog(@"%@",DocumentDir);
return [DocumentDir stringByAppendingPathComponent:DataName];
}
- (void)CopyDatabase
{
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:[self DatabasePath]];
NSString *FileDB = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:DataName];
if (success)
{
NSLog(@"File Exist");
return;
}
else
{
[fileManager copyItemAtPath:FileDB toPath:[self DatabasePath] error:nil];
}
}