1
我用翠鳥的顯示圖像的URL,但我的網址與Authorization頭。 如何使用這些類型的網址與翠鳥或SDWebImage iOS中?使用URL授權頭與翠鳥
我用翠鳥的顯示圖像的URL,但我的網址與Authorization頭。 如何使用這些類型的網址與翠鳥或SDWebImage iOS中?使用URL授權頭與翠鳥
隨着翠鳥你需要使(的AnyModifier
型)的請求修改,並將其傳遞作爲.kf.setImage
方法的options
部分的參數,然後使用所述後閉合實際設置的圖像。
例子:
import Kingfisher
let modifier = AnyModifier { request in
var r = request
// replace "Access-Token" with the field name you need, it's just an example
r.setValue(<YOUR_TOKEN>, forHTTPHeaderField: "Access-Token")
return r
}
let url = URL(string: <YOUR_URL>)
let iView = <YOUR_IMAGEVIEW>
iView.kf.setImage(with: url, options: [.requestModifier(modifier)]) { (image, error, type, url) in
if error == nil && image != nil {
// here the downloaded image is cached, now you need to set it to the imageView
DispatchQueue.main.async {
iView.image = image
}
} else {
// handle the failure
print(error)
}
}
任何人都可以幫我嗎? – sony