您的位置:首页 > 理论基础 > 计算机网络

ASIHTTPRequest 缓存+下载文件到本地

2012-08-20 17:12 465 查看
//路径

-(NSString*) pathToCachedResponseDataForStr:(NSString*)aStr{

NSURL *url = [NSURL URLWithString:aStr];

NSString *temCa = [[ASIDownloadCache sharedCache]pathToCachedResponseDataForURL:url];

#if DEBUG_LOG

NSLog(@"temCa: %@\n",temCa);

#endif

return temCa;

}

//下载文件

-(void)requestDataWithStr:(NSString*)aStr{

NSURL *url = [NSURL URLWithString:aStr];

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];

[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];

[request setSecondsToCache:60*60*24*30];

[request setDownloadDestinationPath:

[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:request]];

[request startAsynchronous];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: