Ios 如何在Alamofire请求中检查来自缓存或服务器的网络响应?
我正在使用Alamofire进行网络呼叫,并在iOS应用程序中缓存响应 响应是缓存,但我无法检查收到的响应是来自缓存还是来自服务器Ios 如何在Alamofire请求中检查来自缓存或服务器的网络响应?,ios,swift,alamofire,Ios,Swift,Alamofire,我正在使用Alamofire进行网络呼叫,并在iOS应用程序中缓存响应 响应是缓存,但我无法检查收到的响应是来自缓存还是来自服务器 如何检查相同的内容?您可以检查是否有任何请求的缓存数据可用或未使用 if let cacheData = URLCache.shared.cachedResponse(for: request) { // Already cached } 你能展示你的代码让我告诉你吗?在dataTaskWillCacheResponseWithCompletion中,我正在
如何检查相同的内容?您可以检查是否有任何请求的缓存数据可用或未使用
if let cacheData = URLCache.shared.cachedResponse(for: request) {
// Already cached
}
你能展示你的代码让我告诉你吗?在dataTaskWillCacheResponseWithCompletion中,我正在设置响应头[“缓存控制”]=“max age=60”,我用同样的方法进行了检查,但总是给我-响应来自服务器,即使我点击脱机请求并从缓存获取数据。下面是代码//如果让cacheData=URLCache.shared.cachedResponse(for:(request.request?.urlRequest!)!){print(“数据来自缓存”)}其他{打印(“数据来自服务器”)}