Kingfisher の通信を Basic 認証に対応させる

  • 2
    Like
  • 0
    Comment

ImageDownloadRequestModifier (AnyModifier) を利用して URLRequest に変更を加えると良い。

var options: KingfisherOptionsInfo = [
        .scaleFactor(UIScreen.main.scale),
        .transition(ImageTransition.fade(0.35)),
        ]

let encodedAuth = 

let modifier: AnyModifier = AnyModifier.init(modify: { (req: URLRequest) -> URLRequest? in
    var r = req
    r.setValue("Basic \(encodedAuth)", forHTTPHeaderField: "Authorization")
    return r
})
options.append(.requestModifier(modifier))

imageView.kf.setImage(with: URL,
              placeholder: placeholder,
              options: options,
              progressBlock: nil,
              completionHandler: nil)