Pass custom Header for download image in SDWebImage iOS sdk

1.1k Views Asked by At

I need to pass custom HTTPHeader for fetch image but getting error 401. Same token is working for other api.

Header is passed in sdwebimage requesturl:

image of debug point

I am passing custom headers like below code.

SDWebImageDownloader *manager = [SDWebImageManager sharedManager].imageDownloader;
[manager setValue:[DefaultsValues getStringValueFromUserDefaults_ForKey:kTokenKey] forHTTPHeaderField:@"authToken"];
[manager setValue:[DefaultsValues getStringValueFromUserDefaults_ForKey:kUserEmail] forHTTPHeaderField:@"email"];
[manager downloadImageWithURL:[NSURL URLWithString:@"URL STRING"] options:SDWebImageDownloaderUseNSURLCache progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {

    NSLog(@"%tu",receivedSize);

} completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
    if (error == nil) {
        cell.profileImage.image = image;
    }
}];
0

There are 0 best solutions below