星空网 > 软件开发 > 操作系统

AFNetworking 3.0 断点续传 使用记录

最近项目中用到了压缩包下载,使用AFNetworking 3.0 下载压缩包 支持断点续传 代码如下:

#import "HDInternet_handler.h"#import "AFNetworking.h"#import "ASIHTTPRequest.h"@interface HDInternet_handler ()<NSURLSessionDelegate>@end@implementation HDInternet_handler{  NSURLSessionDownloadTask *_downloadTask;}-(void)test{  NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration];    manager.requestSerializer.timeoutInterval = 3.0;    [manager setDownloadTaskDidWriteDataBlock:^(NSURLSession * _Nonnull session, NSURLSessionDownloadTask * _Nonnull downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {        LOG(@"%.2f / %.2f",(float)totalBytesWritten/1024.0/1024.0,(float)totalBytesExpectedToWrite/1024.0/1024.0);  }];    NSURL *URL = [NSURL URLWithString:@"http://192.168.10.155/12345/HD_DEMO_RES/CHINESE.zip"];//http://192.168.10.155/12345/HD_DEMO_RES/CHINESE.zip  NSURLRequest *request = [NSURLRequest requestWithURL:URL];    _downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {        NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];    return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];  } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {      }];    [_downloadTask resume];  [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(suspend) userInfo:nil repeats:NO];}-(void)suspend{  //暂停下载  [_downloadTask suspend];  LOG(@"SUSPEND.....SUSPEND....SUSPEND....SUSPEND....SUSPEND....SUSPEND....");  [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(resume) userInfo:nil repeats:NO];}-(void)resume{//继续下载  [_downloadTask resume];  LOG(@"RESUME.....RESUME.....RESUME.....RESUME.....RESUME.....RESUME.....RESUME.....");}

 




原标题:AFNetworking 3.0 断点续传 使用记录

关键词:net

net
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

跨境电商在线培训:https://www.goluckyvip.com/tag/36600.html
跨境电商在线学习培训视频:https://www.goluckyvip.com/tag/36601.html
跨境电商泽宝:https://www.goluckyvip.com/tag/36604.html
跨境电商怎么操作:https://www.goluckyvip.com/tag/36605.html
跨境电商怎么海外宣传:https://www.goluckyvip.com/tag/36606.html
跨境电商怎么开店铺:https://www.goluckyvip.com/tag/36607.html
​TikTok发生了什么?美区增长首次停滞,准入管理力度加大:https://www.kjdsnews.com/a/1836407.html
2024年如何找到在TikTok上发帖的最佳时间:https://www.kjdsnews.com/a/1836408.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流