0
IOS7에서 작동하는이 코드는 장치에 이미지가 있는지 확인하고 그렇지 않은 경우 로컬로 다운로드합니다.로컬로 이미지 저장 IOS8
IOS8은 아무 것도 저장하지 않습니다. 누군가 나를 도울 수 있습니까?
//folder where save
NSString *ImagesPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
// check if image exist
NSString* foofile = [ImagesPath stringByAppendingPathComponent:nombreImagenLocal];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];
// check if image exist locally
if (!fileExists){
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:rutaCompletaLogo]];
//if not, i save it
if (data) {
// url where is saved
NSString *cachedImagePath = [ImagesPath stringByAppendingPathComponent:nombreImagenLocal];
if ([data writeToFile:cachedImagePath atomically:YES]) {
NSLog(@"Downloaded file saved to: %@", cachedImagePath);
}// end
대신'writeToFile : options : error :'를 사용하고 NSError 포인터를 지정하십시오. 그런 다음 NSE 오류를 검사하여 무엇이 잘못되었는지 확인합니다. –
쓰기 오류 Error Domain = NSCocoaErrorDomain Code = 4 "작업을 완료 할 수 없습니다 (코코아 오류 4)."UserInfo = 0x7f8170f37710 {NSFilePath =/사용자/BEhost/라이브러리/개발자/CoreSimulator/장치/66E03424-9959-473C -9912-BEAD2BE9C8A4/data/컨테이너/데이터/응용 프로그램/79C7F75A-7A3C-4C26-88CE-3FC7B3DD12D2/문서 /, NSUserStringVariant = 폴더, NSUnderlyingError = 0x7f817315c590 "작업을 완료 할 수 없습니다. –