• ASIHTTPRequest实现断点下载


    - (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)throttleBand(id)sender
    
    {
    
    if ([(UIButton *)sender state] ==YES) {
    
    [ASIHTTPRequest setMaxBandwidthPerSecond:ASIWWANBandwidthThrottleAmount];
    
    } else {
    
    [ASIHTTPRequest setMaxBandwidthPerSecond:];
    
    }
    
    }
  • 相关阅读:
    泡泡H5这封企业剪彩活动邀请函好像挺专业!
    教你 Shiro + SpringBoot 整合 JWT
    Thymeleaf 获取后端Model中的数据
    SpringBoot 之 普通类获取Spring容器中的bean ,
    如何用JS判断网页中某个id的网页元素是否存在(两种写法 jQuery写法和原始写法:
    前台请求不带cookie的问题解决方案大汇总
    js访问函数内部的变量(三种方法)
    源码分析:若依用户 user_id查询返回除了用户表,为何还带有部门dept和角色role表呢
    关于若依前端分页首次使用BootstrapPager 即bootstrap扩展插件
    关于若依需要验证码,PostMan是如何登陆流程
  • 原文地址:https://www.cnblogs.com/jinlianglu/p/6511403.html
Copyright © 2020-2023  润新知