customDownloadOperation.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // customDownloadOperation.h
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/7/1.
  6. //
  7. #import <Foundation/Foundation.h>
  8. /** 下载状态*/
  9. typedef enum : NSUInteger {
  10. //customDownloadStateWaiting = 0, /** 下载等待中 */
  11. customDownloadStateDoing =0, /** 下载中 */
  12. customDownloadStateSuspended, /** 下载暂停 */
  13. customDownloadStateCompleted, /** 下载完成 */
  14. customDownloadStateFailed, /** 下载失败 */
  15. //customDownloadStateNetWorkFailed, /** 下载时网络中断 */
  16. } customDownloadStateType;
  17. NS_ASSUME_NONNULL_BEGIN
  18. @interface customDownloadOperation : NSObject
  19. /** 绑定的标示及task的创建 */
  20. @property (readonly,nonatomic, copy)NSString *url;
  21. /** 下载任务 */
  22. @property (nonatomic,strong,nullable)NSURLSession *session;
  23. /** 下载任务 */
  24. @property (nonatomic,strong,nullable)NSURLSessionDataTask *dataTask;
  25. @property(nonatomic,assign) BOOL isManualCancel;//手动取消
  26. @property(nonatomic,assign) BOOL isFile404Cancel;//请求文件返回404
  27. /** 文件句柄 可以记录文件的下载的位置 */
  28. @property (nonatomic,strong,nullable) NSFileHandle *handle;
  29. /** 下载的文件总大小 */
  30. @property (nonatomic,assign) int64_t totalSize;
  31. /** 当前下载了多少 */
  32. @property (nonatomic,assign) int64_t currentSize;
  33. /** 当前下载文件名称 */
  34. @property (nonatomic,copy) NSString *fileName;
  35. /** 当前下载文件沙盒全路径 */
  36. @property (nonatomic,copy) NSString *fullPath;
  37. /** 文件下载状态 */
  38. @property (nonatomic,assign) customDownloadStateType downloadState;
  39. /** 下载完成-时间戳 */
  40. @property (nonatomic,assign) NSInteger timeStamp;
  41. /** 文件类型 */
  42. @property (nonatomic,assign) NSInteger fileType;
  43. /** 是否完成 */
  44. @property (nonatomic, assign) NSInteger isFinished;
  45. // 创建下载操作任务
  46. - (instancetype)initWith:(NSString *)url session:(NSURLSession *)session;
  47. - (NSDictionary *)downLoadInfoWithFinished:(BOOL)finished;
  48. @end
  49. NS_ASSUME_NONNULL_END