SDWebImageDownloaderOperation.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import <Foundation/Foundation.h>
  9. #import "SDWebImageDownloader.h"
  10. #import "SDWebImageOperation.h"
  11. FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadStartNotification;
  12. FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadReceiveResponseNotification;
  13. FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadStopNotification;
  14. FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadFinishNotification;
  15. /**
  16. Describes a downloader operation. If one wants to use a custom downloader op, it needs to inherit from `NSOperation` and conform to this protocol
  17. For the description about these methods, see `SDWebImageDownloaderOperation`
  18. */
  19. @protocol SDWebImageDownloaderOperationInterface <NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
  20. @required
  21. - (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)request
  22. inSession:(nullable NSURLSession *)session
  23. options:(SDWebImageDownloaderOptions)options;
  24. - (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
  25. completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock;
  26. - (BOOL)shouldDecompressImages;
  27. - (void)setShouldDecompressImages:(BOOL)value;
  28. - (nullable NSURLCredential *)credential;
  29. - (void)setCredential:(nullable NSURLCredential *)value;
  30. - (BOOL)cancel:(nullable id)token;
  31. @optional
  32. - (nullable NSURLSessionTask *)dataTask;
  33. @end
  34. @interface SDWebImageDownloaderOperation : NSOperation <SDWebImageDownloaderOperationInterface, SDWebImageOperation>
  35. /**
  36. * The request used by the operation's task.
  37. */
  38. @property (strong, nonatomic, readonly, nullable) NSURLRequest *request;
  39. /**
  40. * The operation's task
  41. */
  42. @property (strong, nonatomic, readonly, nullable) NSURLSessionTask *dataTask;
  43. @property (assign, nonatomic) BOOL shouldDecompressImages;
  44. /**
  45. * Was used to determine whether the URL connection should consult the credential storage for authenticating the connection.
  46. * @deprecated Not used for a couple of versions
  47. */
  48. @property (nonatomic, assign) BOOL shouldUseCredentialStorage __deprecated_msg("Property deprecated. Does nothing. Kept only for backwards compatibility");
  49. /**
  50. * The credential used for authentication challenges in `-URLSession:task:didReceiveChallenge:completionHandler:`.
  51. *
  52. * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
  53. */
  54. @property (nonatomic, strong, nullable) NSURLCredential *credential;
  55. /**
  56. * The SDWebImageDownloaderOptions for the receiver.
  57. */
  58. @property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options;
  59. /**
  60. * The expected size of data.
  61. */
  62. @property (assign, nonatomic) NSInteger expectedSize;
  63. /**
  64. * The response returned by the operation's task.
  65. */
  66. @property (strong, nonatomic, nullable) NSURLResponse *response;
  67. /**
  68. * Initializes a `SDWebImageDownloaderOperation` object
  69. *
  70. * @see SDWebImageDownloaderOperation
  71. *
  72. * @param request the URL request
  73. * @param session the URL session in which this operation will run
  74. * @param options downloader options
  75. *
  76. * @return the initialized instance
  77. */
  78. - (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)request
  79. inSession:(nullable NSURLSession *)session
  80. options:(SDWebImageDownloaderOptions)options NS_DESIGNATED_INITIALIZER;
  81. /**
  82. * Adds handlers for progress and completion. Returns a tokent that can be passed to -cancel: to cancel this set of
  83. * callbacks.
  84. *
  85. * @param progressBlock the block executed when a new chunk of data arrives.
  86. * @note the progress block is executed on a background queue
  87. * @param completedBlock the block executed when the download is done.
  88. * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue
  89. *
  90. * @return the token to use to cancel this set of handlers
  91. */
  92. - (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
  93. completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock;
  94. /**
  95. * Cancels a set of callbacks. Once all callbacks are canceled, the operation is cancelled.
  96. *
  97. * @param token the token representing a set of callbacks to cancel
  98. *
  99. * @return YES if the operation was stopped because this was the last token to be canceled. NO otherwise.
  100. */
  101. - (BOOL)cancel:(nullable id)token;
  102. @end