- (IBAction)URLFetchWithProgress:(id)sender
{
[startButton setTitle:@"Stop" forState:UIControlStateNormal];
[startButton addTarget:self action:@selector(stopURLFetchWithProgress:)forControlEvents:UIControlEventTouchUpInside];
NSString*tempFile = [[[[NSBundle mainBundle] bundlePath]stringByDeletingLastPathComponent]stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip.download"];
if ([[NSFileManager defaultManager] fileExistsAtPath:tempFile]) {
[[NSFileManager defaultManager] removeItemAtPath:tempFile error:nil];
}
[self resumeURLFetchWithProgress:self];
}
- (IBAction)stopURLFetchWithProgress:(id)sender
{
networkQueue = [[ASINetworkQueue alloc] init];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:selfselector:@selector(updateBandwidthUsageIndicator) userInfo:nil repeats:YES];
timer = nil;
[startButton setTitle:@"Stop" forState:UIControlStateNormal];
[startButton addTarget:self action:@selector(URLFetchWithProgress:)forControlEvents:UIControlEventTouchUpInside];
[networkQueue cancelAllOperations];
[resumeButton setEnabled:YES];
}
- (IBAction)resumeURLFetchWithProgress:(id)sender
{
[resumeButton setEnabled:NO];
[startButton setTitle:@"Start" forState:UIControlStateNormal];
[startButton addTarget:self action:@selector(stopURLFetchWithProgress:)forControlEvents:UIControlEventTouchUpInside];
[networkQueue cancelAllOperations];
[networkQueue setShowAccurateProgress:YES];
[networkQueue setDownloadProgressDelegate:progressIndicator];
[networkQueue setDelegate:self];
[networkQueue setRequestDidFinishSelector:@selector(URLFetchWithProgressComplete:)];
ASIHTTPRequest*request=[[[ASIHTTPRequest alloc] initWithURL:[NSURLURLWithString:@"http://9991.net/blog/mp3/2.mp3"]] autorelease];
[request setDownloadDestinationPath:[[[[NSBundle mainBundle] bundlePath]
stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"MemexTrails_1.0b1.mp3"]];
[request setTemporaryFileDownloadPath:[[[[NSBundle mainBundle] bundlePath]stringByDeletingLastPathComponent]stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip.down"]];
[request setAllowResumeForFileDownloads:YES];
[networkQueue addOperation:request];
[networkQueue go];
}
- (void)URLFetchWithProgressComplete:(ASIHTTPRequest *)request
{
if ([request error]) {
fileLocation.text=[NSString stringWithFormat:@"An error occurred:%@",[[[requesterror] userInfo] objectForKey:@"Title"]];
} else {
fileLocation.text=[NSString stringWithFormat:@"File downloaded to %@",[requestdownloadDestinationPath]];
}
[startButton setTitle:@"Start" forState:UIControlStateNormal];
[startButton addTarget:self action:@selector(URLFetchWithProgress:)forControlEvents:UIControlEventTouchUpInside];
}
- (IBAction)throttleBandwidth:(id)sender
{
if ([(UIButton *)sender state] ==YES) {
[ASIHTTPRequest setMaxBandwidthPerSecond:ASIWWANBandwidthThrottleAmount];
} else {
[ASIHTTPRequest setMaxBandwidthPerSecond:];
}
}
相关推荐
ASIHTTPRequest实现资源的下载,断点续传
ASIHTTPRequest+UITableView实现多个下载任务,没用到重用机制,还有没有实现断点续载,很简单的一个demo,相信初学者都能看懂,还写了一些注释。
利用ASIHttpRequest实现客户端向服务器端请求登陆验证的示例 博客参考:http://blog.csdn.net/dingxiaowei2013/article/details/12617203
ASIHTTPRequest资源包,下载后添加ASIHTTPRequest相关文件到Xcode项目中
该demo最主要的功能是在用ASIHttpRequest 下载,(当然同样也适用于上传),在弹出的alert框中显示下载(或是上传数据)的进度 在这里注意:如果是下载较大的文件,进度条会缓慢进行;相反如果下载的文件很小,那...
使用ASI开源库,实现队列下载。使用UITableView进行展示
1.基于ASIHttpRequest的断点续传功能,进一步封装,自定义了下载队列,包括下载中、已完成队列,并且用CoreData对其持久化封装,使用简单,资源url作为标示,传入网络资源url和本地path即可。 2.队列使用字典进行...
此为ASIHTTPRequest打包的Frameword,直接导入到工程即可使用。
使用iOS SDK中的HTTP网络请求API,相当的复杂,调用很繁琐,ASIHTTPRequest就是一个对CFNetwork API进行了封装,并且使用起来非常简单的一套API,用Objective-C编写,可以很好的...l 支持断点续传 l 支持同步和异步请求
一款ios实现下载,断点续传的小例子,利用asihttprequest写的,值得学习哦。。。
ASIHTTPRequest是简单易用的,它封装了CFNetwork API。使得与Web服务器通信变得更简单。它是用Objective-C编写的,可以在MAC OS X和iPhone应用中使用。 它适用于执行基本的HTTP请求和互动(或者说是反馈)。...
ASIHTTPREQUEST代码详细下载。
ASIHTTPRequest第三方下载工具,这里写了同步和异步下载的两个实例
ios开发框架 ASIHttpRequest 资源来源于网上 非原创
asihttprequest是目前做移动平台游戏上比较便捷的http通信第三方库
ASIHTTPRequest 源码 、底层构架
IOS基于ASIHttpRequest的封装,使用单例模式断点续传,只需传入要下载的url,即可返回一定时间内的下载进度,错误回调等