0
我想了很多與ASIHTTPRequest
到cache
響應數據,我已經閱讀文檔,並嘗試了很多解決方案,但沒有運氣:(ASIHTTPRequest緩存響應數據
這是我的代碼:
_request = [[ASIFormDataRequest alloc]initWithURL:[NSURL URLWithString:NSLocalizedString(@"kBaseUrl", nil)]];
_request.delegate = self;
[_request setDownloadCache:[ASIDownloadCache sharedCache]];
[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];
[_request setCachePolicy:ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy];//ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy
[_request setSecondsToCache:60*60*24*2]; // Cache for 2 days
[_request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[_request setDefaultResponseEncoding:NSUTF8StringEncoding];
[_request setDidFinishSelector:@selector(doneLoadingBody:)];
[_request setDidFailSelector:@selector(failedLoadingBody:)];
[_request setRequestMethod:@"POST"];
[_request setShouldContinueWhenAppEntersBackground:YES];
[_request setPostValue:@"someValue" forKey:@"name"];
[_request setPostValue:@"someValue" forKey:@"key"];
[_request setPostValue:@"someValue" forKey:@"key"];
[_request startAsynchronous];
if ([_request didUseCachedResponse] == NO) {
NSLog(@"Did not Cache Body");
}
停止使用ASIHTTPRequest並開始使用AFNetworking。幾年來ASI不受支持(我認爲他們甚至沒有ARC支持)。 – Eimantas
@Eimantas我打算轉移到AFNetworking,但目前沒有..我正在使用ASIHTTPRequest處理現有項目,所以在轉移到AFNetworking之前我需要一些時間。 – Atrash