SDWebImageDownloaderOperation.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. */
  18. @protocol SDWebImageDownloaderOperationInterface<NSObject>
  19. - (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)request
  20. inSession:(nullable NSURLSession *)session
  21. options:(SDWebImageDownloaderOptions)options;
  22. - (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
  23. completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock;
  24. - (BOOL)shouldDecompressImages;
  25. - (void)setShouldDecompressImages:(BOOL)value;
  26. - (nullable NSURLCredential *)credential;
  27. - (void)setCredential:(nullable NSURLCredential *)value;
  28. @end
  29. @interface SDWebImageDownloaderOperation : NSOperation <SDWebImageDownloaderOperationInterface, SDWebImageOperation, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
  30. /**
  31. * The request used by the operation's task.
  32. */
  33. @property (strong, nonatomic, readonly, nullable) NSURLRequest *request;
  34. /**
  35. * The operation's task
  36. */
  37. @property (strong, nonatomic, readonly, nullable) NSURLSessionTask *dataTask;
  38. @property (assign, nonatomic) BOOL shouldDecompressImages;
  39. /**
  40. * Was used to determine whether the URL connection should consult the credential storage for authenticating the connection.
  41. * @deprecated Not used for a couple of versions
  42. */
  43. @property (nonatomic, assign) BOOL shouldUseCredentialStorage __deprecated_msg("Property deprecated. Does nothing. Kept only for backwards compatibility");
  44. /**
  45. * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`.
  46. *
  47. * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
  48. */
  49. @property (nonatomic, strong, nullable) NSURLCredential *credential;
  50. /**
  51. * The SDWebImageDownloaderOptions for the receiver.
  52. */
  53. @property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options;
  54. /**
  55. * The expected size of data.
  56. */
  57. @property (assign, nonatomic) NSInteger expectedSize;
  58. /**
  59. * The response returned by the operation's connection.
  60. */
  61. @property (strong, nonatomic, nullable) NSURLResponse *response;
  62. /**
  63. * Initializes a `SDWebImageDownloaderOperation` object
  64. *
  65. * @see SDWebImageDownloaderOperation
  66. *
  67. * @param request the URL request
  68. * @param session the URL session in which this operation will run
  69. * @param options downloader options
  70. *
  71. * @return the initialized instance
  72. */
  73. - (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)request
  74. inSession:(nullable NSURLSession *)session
  75. options:(SDWebImageDownloaderOptions)options NS_DESIGNATED_INITIALIZER;
  76. /**
  77. * Adds handlers for progress and completion. Returns a tokent that can be passed to -cancel: to cancel this set of
  78. * callbacks.
  79. *
  80. * @param progressBlock the block executed when a new chunk of data arrives.
  81. * @note the progress block is executed on a background queue
  82. * @param completedBlock the block executed when the download is done.
  83. * @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
  84. *
  85. * @return the token to use to cancel this set of handlers
  86. */
  87. - (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
  88. completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock;
  89. /**
  90. * Cancels a set of callbacks. Once all callbacks are canceled, the operation is cancelled.
  91. *
  92. * @param token the token representing a set of callbacks to cancel
  93. *
  94. * @return YES if the operation was stopped because this was the last token to be canceled. NO otherwise.
  95. */
  96. - (BOOL)cancel:(nullable id)token;
  97. @end