您的位置:首页 > 其它

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