ASIDownload下载显示的用法
2014-02-15 20:47
543 查看
- (IBAction)downAction:(id)sender
{
NSString *urlstring =
@"http://free2.macx.cn:81/tools/other2/PaintCode132.dmg";
NSURL *url = [NSURL
URLWithString:urlstring];
ASIHTTPRequest *request = [[ASIHTTPRequest
alloc]
initWithURL:url];
[request
setRequestMethod:@"GET"];
NSString *fileName = [urlstring
lastPathComponent];
//文件下载到本地的路径
NSString *filePath = [NSHomeDirectory()
stringByAppendingString:fileName];
//设置下载完成之后文件的存放路径
[request setDownloadDestinationPath:filePath];
//设置进度条视图,显示下载的进度
[request setDownloadProgressDelegate:self.progressView];
//开始异步加载
[request startAsynchronous];
//使用KVO监听精度视图的变化
[self.progressView
addObserver:self
forKeyPath:@"progress"
options:NSKeyValueObservingOptionNew
context:nil];
}
//KVO观察者方法
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
NSNumber *progress = [change
objectForKey:@"new"];
double value = [progress
doubleValue];
self.progressLabel.text = [NSString
stringWithFormat:@"下载进度:%0.1f",value];
}
{
NSString *urlstring =
@"http://free2.macx.cn:81/tools/other2/PaintCode132.dmg";
NSURL *url = [NSURL
URLWithString:urlstring];
ASIHTTPRequest *request = [[ASIHTTPRequest
alloc]
initWithURL:url];
[request
setRequestMethod:@"GET"];
NSString *fileName = [urlstring
lastPathComponent];
//文件下载到本地的路径
NSString *filePath = [NSHomeDirectory()
stringByAppendingString:fileName];
//设置下载完成之后文件的存放路径
[request setDownloadDestinationPath:filePath];
//设置进度条视图,显示下载的进度
[request setDownloadProgressDelegate:self.progressView];
//开始异步加载
[request startAsynchronous];
//使用KVO监听精度视图的变化
[self.progressView
addObserver:self
forKeyPath:@"progress"
options:NSKeyValueObservingOptionNew
context:nil];
}
//KVO观察者方法
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
NSNumber *progress = [change
objectForKey:@"new"];
double value = [progress
doubleValue];
self.progressLabel.text = [NSString
stringWithFormat:@"下载进度:%0.1f",value];
}
相关文章推荐
- 银行总账
- poj2140 连续自然数之和
- IDV学习记录
- NVelocity介绍
- Java初始化(成员变量)
- 双系统,一系统损坏后的解决方案之硬盘启动
- CentOS的u盘安装有u盘才启动,没有u盘无法启动。
- 最简单最易懂的发布网站教程
- android contentProvider
- 《学习OpenCV》练习7-3
- 浅谈HTTP中Get与Post的区别
- ios UITableView中Cell的重用机制
- 1.Android学习笔记-工程目录
- CSS按钮在线生成工具
- error C2556: 'const char &MyString::operator [](int)' : overloaded function differs only by return type from 'char &MyString::operator [](int)'
- java转移字符
- 有个人愿意对你微笑,如果她的眼神是坚定的,她是谁对我其实已经不重要了
- Linux服务器故障排除流程
- Linux远程访问windows时,出现"连接被对端重置"错误
- error C2248: 'MyString::pCharArray' : cannot access private member declared in class 'MyString'