customDownloadOperation.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // customDownloadOperation.h
  3. // Private-X
  4. //
  5. // Created by xd h on 2024/7/1.
  6. //
  7. #import <Foundation/Foundation.h>
  8. //音频播放下载 加入 后续可以单独删除
  9. #import "audioPlayListManager.h"
  10. /** 下载状态*/
  11. typedef enum : NSUInteger {
  12. //customDownloadStateWaiting = 0, /** 下载等待中 */
  13. customDownloadStateDoing =0, /** 下载中 */
  14. customDownloadStateSuspended, /** 下载暂停 */
  15. customDownloadStateCompleted, /** 下载完成 */
  16. customDownloadStateFailed, /** 下载失败 */
  17. //customDownloadStateNetWorkFailed, /** 下载时网络中断 */
  18. } customDownloadStateType;
  19. NS_ASSUME_NONNULL_BEGIN
  20. @interface customDownloadOperation : NSObject
  21. /** 绑定的标示及task的创建 */
  22. @property (readonly,nonatomic, copy)NSString *url;
  23. /** 下载任务 */
  24. @property (nonatomic,strong,nullable)NSURLSession *session;
  25. /** 下载任务 */
  26. @property (nonatomic,strong,nullable)NSURLSessionDataTask *dataTask;
  27. @property(nonatomic,assign) BOOL isManualCancel;//手动取消
  28. @property(nonatomic,assign) BOOL isFile404Cancel;//请求文件返回404
  29. /** 文件句柄 可以记录文件的下载的位置 */
  30. @property (nonatomic,strong,nullable) NSFileHandle *handle;
  31. /** 下载的文件总大小 */
  32. @property (nonatomic,assign) int64_t totalSize;
  33. /** 当前下载了多少 */
  34. @property (nonatomic,assign) int64_t currentSize;
  35. /** 当前下载文件名称 */
  36. @property (nonatomic,copy) NSString *fileName;
  37. /** 当前下载文件沙盒全路径 */
  38. @property (nonatomic,copy) NSString *fullPath;
  39. /** 文件下载状态 */
  40. @property (nonatomic,assign) customDownloadStateType downloadState;
  41. /** 下载完成-时间戳 */
  42. @property (nonatomic,assign) NSInteger timeStamp;
  43. /** 文件类型 */
  44. @property (nonatomic,assign) NSInteger fileType;
  45. /** 是否完成 */
  46. @property (nonatomic, assign) NSInteger isFinished;
  47. /** 下载中上次通知的时间 用来控制通知时间的频率 目前定位一秒 */
  48. @property (nonatomic, assign) NSTimeInterval preNotTimeInterval;
  49. // 创建下载操作任务
  50. - (instancetype)initWith:(NSString *)url session:(NSURLSession *)session;
  51. // downloadType 不传 即为原来的 分享链接唤起的下载
  52. // downloadType audioPlayCache 为音乐播放下载缓存
  53. - (instancetype)initWith:(NSString *)url session:(NSURLSession *)session withType:(NSString*)downloadType;
  54. - (NSDictionary *)downLoadInfoWithFinished:(BOOL)finished;
  55. @end
  56. NS_ASSUME_NONNULL_END