现在的位置: 首页 > 综合 > 正文

ASIHTTPRequest 缓存+下载文件到本地

2013年02月22日 ⁄ 综合 ⁄ 共 765字 ⁄ 字号 评论关闭

//路径
-(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];
}

抱歉!评论已关闭.