我正在尝试加载此jpeg:https://i.groupme.com/638x640.jpeg.d4f31c747b534baca03d12db5a2b6193
但我收到错误The operation couldn’t be completed. (NSURLErrorDomain error -1100.)
从this post,我发现错误意味着:kCFURLErrorFileDoesNotExist
。这很奇怪,因为那里肯定有一个图像。
来自this post,似乎问题出在https
协议上,但在我实施解决方案以切换到http
之后,我收到了错误:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
... The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
在进行必要的plist更改后,同样的错误会继续弹出:
如何在iOS下载此图像?
更新
因此,如果我使用此代码,我发现使用https
下载确定:
NSData* theData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://i.groupme.com/638x640.jpeg.d4f31c747b534baca03d12db5a2b6193"]];
UIImage *image = [UIImage imageWithData:theData];
但如果我使用此库则无效:https://github.com/rs/SDWebImage
似乎没有其他人遇到https
和那个库的问题,所以我认为它仍然是我的设置问题?
答案 0 :(得分:5)
您提供的域名错误。
删除您手动添加的所有plist设置,将其添加到plist ----
中 <key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>i.groupme.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<false/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSRequiresCertificateTransparency</key>
<false/>
</dict>
</dict>
</dict>
Plist屏幕截图
NSURL *url = [[NSURL alloc] initWithString:@"https://i.groupme.com/638x640.jpeg.d4f31c747b534baca03d12db5a2b6193"];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *result = [[UIImage alloc] initWithData:data];