【发布时间】:2016-09-29 21:47:52
【问题描述】:
我正在尝试使用 Alamofire 缓存,所以我想要的行为是第一次从 Web 加载,下一次如果缓存中存在数据,则返回它而不发出更多请求……在我考虑过期之后...
我的代码总是返回无响应...对此有什么建议吗?谢谢
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
config.URLCache = NSURLCache.sharedURLCache()
config.requestCachePolicy = NSURLRequestCachePolicy.ReturnCacheDataElseLoad
let manager = Alamofire.Manager(configuration: config)
manager.request(.GET, url, parameters: parameters, encoding: .URL, headers: ["Token":LocalStorage.read("token") as! String, "Version":"2"]).responseJSON { (response) in
if let json = response.result.value
{
if response.response?.statusCode == 200
{
completionHandler(parser.parseSwifty(JSON(json)), nil)
}
else
{
completionHandler(nil, serverErrorMessage)
}
}
else
{
completionHandler(nil, networkErrorMessage)
}
}
【问题讨论】: