MainBundle/SampleImages フォルダからアプリケーションの NSDocumentDirectory/Library フォルダにいくつかの画像ファイルをコピーしようとしていますが、コピーできません。画像が .app/Mainbundle/SampleImages ディレクトリにあることを確認し、Library フォルダーが NSDocumentsDirectory に作成されていることも確認しましたが、ファイルはコピーされません。
以下に示す2つのアプローチを試しましたが、成功しませんでした。これは、ファイルをコピーするために使用しているコードです。
最初の方法
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentLibraryFolderPath = [documentsDirectory stringByAppendingPathComponent:@"Library"];
NSString *resourceSampleImagesFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"SampleImages"];
NSData *mainBundleFile = [NSData dataWithContentsOfFile:resourceSampleImagesFolderPath];
[[NSFileManager defaultManager] createFileAtPath:documentLibraryFolderPath
contents:mainBundleFile
attributes:nil];
2番目の方法
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentSampleImagesFolderPath = [documentsDirectory stringByAppendingPathComponent:@"Library"];
NSString *resourceSampleImagesFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"SampleImages/"];
[fileManager createDirectoryAtPath: documentSampleImagesFolderPath attributes:nil];
if([fileManager copyItemAtPath:resourceSampleImagesFolderPath toPath:documentSampleImagesFolderPath error:&error]) {
NSLog(@"success");
}
else {
NSLog(@"Failure");
NSLog(@"%d",error);
}
解決策を探すのに数時間を費やしました。ここで何か助けていただければ幸いです。
ありがとうございました
シュマイス・ウル・ハク