2017-05-29 36 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) 
    } 
}