1

I'm using this method to assign a YouTube video thumbnail to an image view in a custom collection cell view:

  [cell.imageView sd_setImageWithURL:[NSURL URLWithString:youtubeImageString]
                  placeholderImage:nil
                         completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                             if (cacheType != SDImageCacheTypeMemory)
                             {
                                 cell.imageView.alpha = 0.0;
                                 double val = ((double)arc4random()/ARC4RANDOM_MAX)*0.8;
                                 [UIView animateWithDuration:0.2 delay:val options:UIViewAnimationOptionCurveEaseInOut animations:^{
                                     cell.imageView.alpha = 1.0;
                                 } completion:nil];
                             }
                         }];

When I build and run my application, I'll get an empty cell. I have debugged the code with break points, and the URL is correct and the JSON data is there, but the images are not showing.

Debugging

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • "the url is correct " : What's the value of `[NSURL URLWithString:youtubeImageString]`? Did you read the `error` param of the block? – Larme Aug 31 '17 at 14:37
  • @Larme that's the value: http://img.youtube.com/vi/8e0jlmHVUyY/hqdefault.jpg and what do you mean by "read the error param of the block?" –  Aug 31 '17 at 14:47
  • The the `completed` block, is error nil? You did only `if (cacheType != SDImageCacheTypeMemory)`, but is `error` nil there? Is your issue only related to the animation? If you remove the animation, does it work? – Larme Aug 31 '17 at 14:48
  • @Larme no it's not nil, it gives me an NSURLErrorDomain: NSError NSError domain: @"NSURLErrorDomain" - code: 18446744073709550594 and no even if I remove the animation still doesn't show any images. –  Aug 31 '17 at 14:57
  • @Larme could it be because it's a http url ? –  Aug 31 '17 at 14:58
  • @TahaAmini, I think you have to add some AppTransport Security setting in your App in order to access image using URL. Please go through the below url https://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9 – Prakash Aug 31 '17 at 15:06
  • @Prakash yup it's working now , thanks ! –  Aug 31 '17 at 15:15
  • 1
    @TahaAmini, PLease accept my anwser if it has solved your issue. – Prakash Aug 31 '17 at 15:16
  • @Prakash okay, write it as an answer and I will accept it –  Aug 31 '17 at 15:27
  • @Larme thank you for your help also –  Aug 31 '17 at 15:27

1 Answers1

0

You can add exceptions for specific domains in your Info.plist:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>testdomain.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>
Prakash
  • 157
  • 10