NSHomeDirectory の下にフォルダーを作成するコードがありますが、常に失敗し、理由がわかりません。動作するはずですが、操作は許可されていないと言い続けます。何か案は?
NSURL *homeURL = [NSURL fileURLWithPath:NSHomeDirectory() isDirectory:YES];
NSURL *previewsURL = [homeURL URLByAppendingPathComponent:@"Previews"];
DebugLog(@"homeURL: %@", homeURL);
DebugLog(@"previewsURL: %@", previewsURL);
BOOL isDirectory = TRUE;
if (![[NSFileManager defaultManager] fileExistsAtPath:previewsURL.path isDirectory:&isDirectory]) {
DebugLog(@"isDirectory: %@", isDirectory ? @"YES" : @"NO");
NSAssert(isDirectory, @"Must be a directory");
NSError *error = nil;
if (![[NSFileManager defaultManager] createDirectoryAtPath:previewsURL.path withIntermediateDirectories:TRUE attributes:nil error:&error]) {
DebugLog(@"Error: %@", error); // WHY?!
}
else {
BOOL isDirectory = TRUE;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:previewsURL.path isDirectory:&isDirectory];
NSAssert(exists, @"Directory must exist");
}
}