iOS Swift Alamofire 缓存策略

标签 ios swift alamofire

Alamofire 版本 3 中,我使用 NSURLRequest.CachePolicy.returnCacheDataDontLoad 进行请求缓存

let URLRequest = NSMutableURLRequest(url: URL(string: url)!)
    URLRequest.cachePolicy = NSURLRequest.CachePolicy.returnCacheDataDontLoad
    Alamofire.request(URLRequest){...}

但是我如何在 Alamofire 4 和 swift 3 中使用 cachePolicy?

谢谢

最佳答案

我到处搜索,结果是这样的:

    let TheURL = DEFAULT_APP_URL + "api/getList?Id="+ID
    let urlString = NSURL(string: TheURL)
    var mutableURLRequest = URLRequest(url: urlString! as URL)
    mutableURLRequest.httpMethod = "GET"
    mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
    mutableURLRequest.cachePolicy = NSURLRequest.CachePolicy.returnCacheDataElseLoad


    Alamofire.request(mutableURLRequest)
        .responseJSON
       {....}

关于iOS Swift Alamofire 缓存策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39976416/

相关文章:

ios - 分别通过alamofire调用web服务

ios - 标量属性在源存储库中除外

ios - 调整 uiview 的背景图像取决于文本

ios - 如何检查相机是否打开以捕获图像或在 iOS 中录制视频?

ios - 适用于 iOS 的旧 Admob 下载链接

ios - ios swift中的搜索栏

swift 2 : UICollectionView - is it possible to return cell asynchronously?

swift - 参数标签(_ :, 目标)与可用重载不匹配

仅限 SWIFT——从 NSInputStream 读取

swift - 如何在 swift3 alamofire 中设置 Content-Type