When I send a request to my rails server and do not receive 304, it does not return the status status of the response to the almofire object. How can I modify my request to get the status code 304 that my rails server returns? I installed Alamofire using cocoapods.
EDIT
This is my code currently (not working):
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() } else {
This is the code after kpsharp's answer (doesn't work):
if Reachability.isConnectedToNetwork() { let urlreq = NSMutableURLRequest(URL: NSURL(string: API.feedURL()+"?category_name=Popular")!,cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData , timeoutInterval: 5000) urlreq.HTTPMethod = "GET" let headers = API.getHeaders() for (key,value) in headers { urlreq.setValue(value, forHTTPHeaderField: key) } urlreq.cachePolicy = .ReloadIgnoringLocalAndRemoteCacheData Alamofire.request(urlreq) } else {
EDIT 2
My caching rails code is:
def index battles = Battle.feed(current_user, params[:category_name], params[:future_time]) @battles = paginate battles, per_page: 50 if stale?([@battles, current_user.id], template: false) render 'index' end end
thanks
gal
source share