2017-05-29 35 views
1

我用翠鳥的顯示圖像的URL,但我的網址與Authorization頭。 如何使用這些類型的網址與翠鳥或SDWebImage iOS中?使用URL授權頭與翠鳥

+0

任何人都可以幫我嗎? – sony

回答

1

隨着翠鳥你需要使(的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) 
    } 
}