1

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:

enter image description here

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?

Community
  • 1
  • 1
Cbas
  • 5,535
  • 11
  • 51
  • 77
  • Possible duplicate of [Transport Security has Blocked a cleartext HTTP](http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http) – EI Captain v2.0 Apr 19 '16 at 05:29
  • if you're trying to close this, explain why. If you read the whole question, you'd know it's not a duplicate of that other question – Cbas Apr 19 '16 at 05:33
  • Your URL contains https so there is no issues for `NSExceptionAllowsInsecureHTTPLoads`. Please show me the code to help you out.... It must work work with https not need to go to http.... – Nirav Gadhiya Apr 19 '16 at 05:43
  • @NiravGadhiya thanks for the tip, after simplifying my code to provide an example, I got it to download. It seems the problem only occurs with the image loading library I am using, but they have an `https` url in their example code, so maybe its probably still a problem on my end https://github.com/rs/SDWebImage – Cbas Apr 19 '16 at 05:55

1 Answers1

5

You are providing a wrong domain name.

Solution

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

enter image description here

Code to download image

 NSURL *url = [[NSURL alloc] initWithString:@"https://i.groupme.com/638x640.jpeg.d4f31c747b534baca03d12db5a2b6193"];
 NSData *data = [[NSData alloc] initWithContentsOfURL:url];
 UIImage *result = [[UIImage alloc] initWithData:data];

Image download Success screenshot

enter image description here

Vizllx
  • 8,843
  • 1
  • 36
  • 77
  • doesn't `NSIncludesSubdomains` include the `i.` part? – Cbas Apr 19 '16 at 05:52
  • Thanks! I just used that code and it worked, seems to have been the library I was using. However, I'm still confused as to why this library doesn't work for me: https://github.com/rs/SDWebImage. They have `https` in their example code, so this is definitely still a problem on my end. – Cbas Apr 19 '16 at 06:04