Search code examples
iosswiftsdwebimage

How to Pass Authtoken while loading Image using SDWebImage


My code is

self.imgProfile.sd_setImage(with: URL(string: "imageURL"), placeholderImage: UIImage(named: "ic_UserDefault"))

I am using default image lazy loading function to laod image.

Pods: pod 'SDWebImage' (Objective C)


Solution

  • You need to set the value of your token in the httpHeader in the request SDWebImageDownloader shared instance have a method to do that

    Swift implementation

    SDWebImageDownloader.shared()?.setValue(value: String!, forHTTPHeaderField: String!)
    

    Objective C example

    [[SDWebImageDownloader sharedDownloader] setValue:"Value" forHTTPHeaderField:"Token"];
    

    After your login you should configure the SDWebImageDownloader passing your received AuthToken