웹에서 이미지를 다운로드하는 간단한 간단한 코드가 있습니다. iOS 8에서는 정상적으로 작동했지만 이제는 iOS 9을 사용하는 Xcode 7.3에서이 오류가 계속 발생합니다. 버그입니까?버그 Xcode 7.3 with iOS 9.2 dataWithContentsOfURL
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
NSString* documentsPath = [paths objectAtIndex:0];
NSError *error;
NSString *data2URL = @"http://cdn.minecraftpocket-servers.com/images/flags/Brazil.png";
NSURL *url = [NSURL URLWithString:data2URL];
NSString *imgFileNameStr = [data2URL lastPathComponent];
NSData *data2 = [NSData dataWithContentsOfURL:url options: NSDataReadingUncached error: &error];
if (error)
NSLog(@"Download error: %@",error);
//check
if (data2 == NULL)
{
NSLog(@"DATA IS NULL");
}
else
{
NSLog(@"DATA IS NOT NULL");
}
//saving file
NSString* fullPathToFile2 = [documentsPath stringByAppendingPathComponent:imgFileNameStr];
BOOL success = [data2 writeToFile:fullPathToFile2 atomically:NO];
NSLog(@"Success = %d ...", success);
ERROR :
2016-07-03 23:00:36.963 014-test-proj[15404:419151] Download error: Error Domain=NSCocoaErrorDomain Code=256 "The file “Brazil.png” couldn’t be opened." UserInfo={NSURL=http://cdn.minecraftpocket-servers.com/images/flags/Brazil.png}
2016-07-03 23:00:36.963 014-test-proj[15404:419151] DATA IS NULL
2016-07-03 23:00:36.964 014-test-proj[15404:419151] Success = 0 ...
는 이미 &는 애플리케이션 보안에 대한 내 PLIST 파일의 확인했다 확인했다.
사람이 같은 문제 HERE했다. 내가 놓친 게 무엇입니까?
업데이트 :이 링크를 사용하는 경우 코드가 작동 ...
NSString *data2URL [email protected]"https://upload.wikimedia.org/wikipedia/commons/1/1e/Large_Siamese_cat_tosses_a_mouse.jpg";
나는 그것을 얻지 않는다. 왜 다른 하나와 문제가 있을까요?
아니를 사용하지 않도록 Info.plist 파일에 다음을 추가합니다. 코드를 NSURLSession으로 변경했지만 파일을 다운로드했지만 열 수 없습니다. 다른 일이 있습니다. 직접 해보십시오. 추신. 업데이트 된 링크보기 –
리디렉션이 있습니다. 아마 그것과 관련이 있습니다. – matt