YYWebImageOperation.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // YYWebImageOperation.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 15/2/15.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. #if __has_include(<YYKit/YYKit.h>)
  13. #import <YYKit/YYImageCache.h>
  14. #import <YYKit/YYWebImageManager.h>
  15. #else
  16. #import "YYImageCache.h"
  17. #import "YYWebImageManager.h"
  18. #endif
  19. NS_ASSUME_NONNULL_BEGIN
  20. /**
  21. The YYWebImageOperation class is an NSOperation subclass used to fetch image
  22. from URL request.
  23. @discussion It's an asynchronous operation. You typically execute it by adding
  24. it to an operation queue, or calls 'start' to execute it manually. When the
  25. operation is started, it will:
  26. 1. Get the image from the cache, if exist, return it with `completion` block.
  27. 2. Start an URL connection to fetch image from the request, invoke the `progress`
  28. to notify request progress (and invoke `completion` block to return the
  29. progressive image if enabled by progressive option).
  30. 3. Process the image by invoke the `transform` block.
  31. 4. Put the image to cache and return it with `completion` block.
  32. */
  33. @interface YYWebImageOperation : NSOperation
  34. @property (nonatomic, strong, readonly) NSURLRequest *request; ///< The image URL request.
  35. @property (nullable, nonatomic, strong, readonly) NSURLResponse *response; ///< The response for request.
  36. @property (nullable, nonatomic, strong, readonly) YYImageCache *cache; ///< The image cache.
  37. @property (nonatomic, strong, readonly) NSString *cacheKey; ///< The image cache key.
  38. @property (nonatomic, readonly) YYWebImageOptions options; ///< The operation's option.
  39. /**
  40. Whether the URL connection should consult the credential storage for authenticating
  41. the connection. Default is YES.
  42. @discussion This is the value that is returned in the `NSURLConnectionDelegate`
  43. method `-connectionShouldUseCredentialStorage:`.
  44. */
  45. @property (nonatomic) BOOL shouldUseCredentialStorage;
  46. /**
  47. The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`.
  48. @discussion This will be overridden by any shared credentials that exist for the
  49. username or password of the request URL, if present.
  50. */
  51. @property (nullable, nonatomic, strong) NSURLCredential *credential;
  52. /**
  53. Creates and returns a new operation.
  54. You should call `start` to execute this operation, or you can add the operation
  55. to an operation queue.
  56. @param request The Image request. This value should not be nil.
  57. @param options A mask to specify options to use for this operation.
  58. @param cache An image cache. Pass nil to avoid image cache.
  59. @param cacheKey An image cache key. Pass nil to avoid image cache.
  60. @param progress A block invoked in image fetch progress.
  61. The block will be invoked in background thread. Pass nil to avoid it.
  62. @param transform A block invoked before image fetch finished to do additional image process.
  63. The block will be invoked in background thread. Pass nil to avoid it.
  64. @param completion A block invoked when image fetch finished or cancelled.
  65. The block will be invoked in background thread. Pass nil to avoid it.
  66. @return The image request opeartion, or nil if an error occurs.
  67. */
  68. - (instancetype)initWithRequest:(NSURLRequest *)request
  69. options:(YYWebImageOptions)options
  70. cache:(nullable YYImageCache *)cache
  71. cacheKey:(nullable NSString *)cacheKey
  72. progress:(nullable YYWebImageProgressBlock)progress
  73. transform:(nullable YYWebImageTransformBlock)transform
  74. completion:(nullable YYWebImageCompletionBlock)completion NS_DESIGNATED_INITIALIZER;
  75. - (instancetype)init UNAVAILABLE_ATTRIBUTE;
  76. + (instancetype)new UNAVAILABLE_ATTRIBUTE;
  77. @end
  78. NS_ASSUME_NONNULL_END