Im trying to create some caching in my app. This is the flow: The user enter the app, the app checks weather are any changes since his last refresh, if yes, the server returns 200 and the page is refreshed. Otherwise, the server returns 304 and nothing happens. I'm using alamofire in the ios app and I tried any configuration in it but nothing helps. The real bizarre issue is that even when the server returns explicitly status code 304, my app still gets 200. This is code:
if Reachability.isConnectedToNetwork() {
let urlreq = NSMutableURLRequest(URL: NSURL(string: API.feedURL())!,cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData
, timeoutInterval: 5000)
Alamofire.request(.GET, urlreq, parameters: ["category_name":category],encoding: ParameterEncoding.URL, headers: API.getHeaders())
.validate(statusCode: 200..<500)
.responseJSON { request, response, result in
switch result {
case .Success(let data):
let statusCode = response!.statusCode as Int!
if statusCode == 304 {
completionHandler(didModified: false, battlesArray: [])
} else if statusCode == 200 {
let json = JSON(data)
var battlesArray : [Battle] = []
for (_,subJson):(String, JSON) in json["battles"] {
battlesArray.append(Battle(json: subJson))
}
completionHandler(didModified: true, battlesArray: battlesArray)
}
case .Failure(_, let error):
print ("error with conneciton:\(error)")
}
SVProgressHUD.dismiss()}
I'm trying to figure out a way to solve it for over a week! Shouldn't be so complicated Hope for help guys