O NSURLCache não limpa as respostas armazenadas no iOS8
Aqui está a função de exemplo que eu chamo quando preciso limpar o cache e fazer uma nova chamada para o URL
- (void)clearDataFromNSURLCache:(NSString *)urlString
{
NSURL *requestUrl = [NSURL URLWithString:urlString];
NSURLRequest *dataUrlRequest = [NSURLRequest requestWithURL: requestUrl];
NSURLCache * cache =[NSURLCache sharedURLCache];
NSCachedURLResponse* cacheResponse =[cache cachedResponseForRequest:dataUrlRequest];
if (cacheResponse) {
NSString* dataStr = [NSString stringWithUTF8String:[[cacheResponse data] bytes]];
NSLog(@"data str r= %@",dataStr);
NSLog(@"url str r= %@",[[[cacheResponse response] URL] absoluteString]);
[cache storeCachedResponse:nil forRequest:dataUrlRequest];
[NSURLCache setSharedURLCache:cache];
}
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:dataUrlRequest];
//Check if the respnase data has been removed/deleted from cache
NSURLRequest *finalRequestUrlRequest = [NSURLRequest requestWithURL:requestUrl];
NSURLCache * finalCache =[NSURLCache sharedURLCache];
NSCachedURLResponse* finalcacheResponse =[finalCache cachedResponseForRequest:finalRequestUrlRequest];
if (finalcacheResponse) {
//Should not enter here
NSString* finaldataStr = [NSString stringWithUTF8String:[[finalcacheResponse data] bytes]];
NSLog(@"data str r= %@",finaldataStr);
NSLog(@"url str r= %@",[[[cacheResponse response] URL] absoluteString]);
}
}
No iOS 6/7, a resposta é excluída com sucesso para o requestURL, mas no iOS 8 nunca é excluída. Eu procurei, mas não consegui encontrar um motivo para isso não funcionar no iOS8.
Qualquer ajuda será apreciada…..