Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To set custom HTTP headers with SDWebImage, you need to use the SDWebImageDownloader class to customize the download operations. Here's an example:

// Create a custom NSURLSessionConfiguration
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.HTTPAdditionalHeaders = @{ @"Authorization": @"Token myToken" };

// Create a custom downloader using the configuration
SDWebImageDownloader *downloader = [[SDWebImageDownloader alloc] initWithSessionConfiguration:configuration];

// Use the downloader to load the image with the custom headers
[imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
             placeholderImage:nil
                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                        // Completion block code here
                    }];

In this example, we create a custom NSURLSessionConfiguration that includes an Authorization header with a token value. We then create a custom SDWebImageDownloader using this configuration and use it to load the image. The custom headers will be sent with the HTTP request for the image.