最初の起動時に、アプリバンドルからドキュメントディレクトリにいくつかのファイルをコピーしようとしています。最初の起動時にチェックを行っていますが、わかりやすくするためにコードスニペットには含まれていません。問題は、ドキュメントディレクトリ(すでに存在している)にコピーしていることであり、ドキュメントには次のように記載されています。
dstPathは、操作の前に存在してはなりません。
ドキュメントルートに直接コピーするための最良の方法は何ですか?これを実行したい理由は、iTunesファイル共有のサポートを許可するためです。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Populator"];
NSLog(@"\nSource Path: %@\nDocuments Path: %@", sourcePath, documentsDirectory);
NSError *error = nil;
if([[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:documentsDirectory error:&error]){
NSLog(@"Default file successfully copied over.");
} else {
NSLog(@"Error description-%@ \n", [error localizedDescription]);
NSLog(@"Error reason-%@", [error localizedFailureReason]);
}
...
return YES;
}
ありがとう