ios – 使用翠鸟lib插入授权标题字段
发布时间:2020-12-14 18:04:50 所属栏目:百科 来源:网络整理
导读:我正在使用Kingfisher来显示来自网址的图片,但我的端点需要一个授权标头. 如何在iOS中使用Kingfisher或SDWeb Image这些网址? 解决方法 使用Kingfisher,您需要创建一个请求修饰符(类型为AnyModifier)并将其作为参数传递给.kf.setImage方法的options部分,然后
我正在使用Kingfisher来显示来自网址的图片,但我的端点需要一个授权标头.
如何在iOS中使用Kingfisher或SDWeb Image这些网址? 解决方法
使用Kingfisher,您需要创建一个请求修饰符(类型为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) } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – 如何判断IQueryable是否为IOrderedQueryable?
- flash as3输出并执行javascript
- 写给安卓程序员的C/C++编译入门
- 在vb.net控制台exe中获取启动路径
- 在Wildfly中,在我的WAR中包含JAR文件与通过jboss-deploymen
- XML 导入 Sqlite 遇到的强大工具Navicat
- Flash Memory: NAND, EEPROM, NVRAM and others
- PostgreSQL 9.6.1,9.5.5,9.4.10,9.3.15,9.2.19和9.1.24
- 如何将C#dll导入python
- flex 调用c#webservice