2017-05-29 10 views
1

私はキングフィッシャーをURLからの表示用画像に使用していますが、私のURLには認証ヘッダーがあります。 iOSでKingfisherまたはSDWebImageでこれらの種類のURLを使用するにはどうすればよいですか?キングフィッシャーで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) 
    } 
}