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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-08-14 11:00:00 +0000
Seen: 17 times
Last updated: May 13 '22
How can a custom CSS stylesheet be incorporated into Tailwind CSS?
How do you call a method in a custom view from a ViewModel?
After transitioning from Angular 7 to 8, why are custom fonts failing to load?
How can one develop a custom control for WPF?