| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //
- // customDownloadOperation.m
- // 双子星云手机
- //
- // Created by xd h on 2024/7/1.
- //
- #import "customDownloadOperation.h"
- #import "customDownloadCacheManager.h"
- #import "NSURLSession+customDownloadTask.h"
- @implementation customDownloadOperation
- - (instancetype)initWith:(NSString *)url session:(NSURLSession *)session{
-
- if (self = [super init]) {
- _url = url;
- // 初始化下载信息
- // 拼接后缀名
- NSString *urlFileName = [url lastPathComponent];
- NSString * decodeUrlFileName= [urlFileName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- self.fileName = decodeUrlFileName;
-
- NSString* fileFullDir = [customDownloadCacheManager getFullDirector];
- // 创建文件储存路径
- if (![[NSFileManager defaultManager] fileExistsAtPath:fileFullDir]) {
- [[NSFileManager defaultManager] createDirectoryAtPath:fileFullDir withIntermediateDirectories:YES attributes:nil error:nil];
- }
- // 设置下载路径
- self.fullPath = [fileFullDir stringByAppendingPathComponent:self.fileName];
-
- _currentSize = [customDownloadCacheManager getFileSizeWithURL:url];
-
- // 偏好设置里面存储总数据
- //_totalSize = 0;
-
- _timeStamp = [iTools getNowTimeStamp];
- // 校验
- if (self.currentSize == self.totalSize && self.totalSize != 0) {
- return nil;
- }
-
-
- _downloadState = customDownloadStateDoing;
-
- _session = session;
- _dataTask = [_session custom_downloadDataTaskWithURLString:url startSize:_currentSize];
- }
- return _dataTask ? self : nil;
- }
- #pragma mark - setups
- @end
|