". 동작 (코코아 오류 512)을 완료 할 수 없습니다",하지만 난 udnerstand 수 없습니다는 내가 완벽하게 작동해야이 코드를 가지고
+(NSString *)writeImageToFile:(UIImage *)image {
NSData *fullImageData = UIImageJPEGRepresentation(image, 1.0f);
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Images/"];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDirectory = NO;
BOOL directoryExists = [fileManager fileExistsAtPath:path isDirectory:&isDirectory];
if (directoryExists) {
NSLog(@"isDirectory: %d", isDirectory);
} else {
NSError *error = nil;
BOOL success = [fileManager createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:&error];
if (!success) {
NSLog(@"Failed to create directory with error: %@", [error description]);
}
}
NSString *name = [NSString stringWithFormat:@"%@.jpg", [JEntry generateUuidString]];
NSString *filePath = [path stringByAppendingPathComponent:name];
NSError *error = nil;
BOOL success = [fullImageData writeToFile:filePath options:NSDataWritingAtomic error:&error];
if (!success) {
NSLog(@"Failed to write to file with error: %@", [error description]);
}
return filePath;
}
이 오류없이 directoryExists을 통과하지만 writeToFile에 도달 할 때, 그것은 나에게이 오류 제공 :
Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x5634ee0 {NSFilePath=/var/mobile/Applications/5E25F369-9E05-4345-A0A2-381EDB3321B8/Documents/Images/18DAE0BD-6CB4-4244-8ED1-9031393F6DAC.jpg, NSUnderlyingError=0x5625010 "The operation couldn’t be completed. Not a directory"}
모든 아이디어는 이유가 될 수 있습니까?
첫 번째 해결책은 맞았습니다. 고마워. :) – Andrew
@sch : 그날 늦게 나도 알아,하지만 고마워. 내 문제는 내 코드가 iPad에서는 잘 실행되었지만 시뮬레이터에서는 제대로 실행되지 못했습니다. 내용 및 설정 재설정으로 문제가 해결되었습니다. – Robert
나는 2) 문제가 있었다. 하지만 처음에는 컴파일러에 영구 저장소가 없다고 말합니다. 이제 영구 저장소를 추가하려고합니다. 이미 가지고 있기 때문에 코코아 오류 512와 함께 실패합니다! 뭐야! – coolcool1994