I am trying to load this jpeg: https://i.groupme.com/638x640.jpeg.d4f31c747b534baca03d12db5a2b6193
but I get the error The operation couldn’t be completed. (NSURLErrorDomain error -1100.)
From this post, I found the error means: kCFURLErrorFileDoesNotExist
. which is strange because there is definitely an image there.
From this post, it seemed the issue was with the https
protocol, but after I implemented the solution to switch to http
, I got the error:
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.
And the same error continues to popup after making the necessary plist changes:
How do I download this image in iOS?
UPDATE
So I found that it does download OK with https
if I use this code:
NSData* theData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://i.groupme.com/638x640.jpeg.d4f31c747b534baca03d12db5a2b6193"]];
UIImage *image = [UIImage imageWithData:theData];
but it doesn't work if I use this library: https://github.com/rs/SDWebImage
No one else seems to have had issues with https
and that library though, so I think its still a settings problem on my end?
You are providing a wrong domain name.
Delete all the plist settings you have added manually, add this in 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 Screenshot
NSURL *url = [[NSURL alloc] initWithString:@"https://i.groupme.com/638x640.jpeg.d4f31c747b534baca03d12db5a2b6193"];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *result = [[UIImage alloc] initWithData:data];