chengyanfang

sdk upgrade

Showing 31 changed files with 3099 additions and 0 deletions
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +
  11 +#if HH_MAC
  12 +
  13 +// A subclass of `NSBitmapImageRep` to fix that GIF loop count issue because `NSBitmapImageRep` will reset `NSImageCurrentFrameDuration` by using `kCGImagePropertyGIFDelayTime` but not `kCGImagePropertyGIFUnclampedDelayTime`.
  14 +// Built in GIF coder use this instead of `NSBitmapImageRep` for better GIF rendering. If you do not want this, only enable `HHWebImageImageIOCoder`, which just call `NSImage` API and actually use `NSBitmapImageRep` for GIF image.
  15 +
  16 +@interface HHAnimatedImageRep : NSBitmapImageRep
  17 +
  18 +@end
  19 +
  20 +#endif
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageCompat.h"
  11 +#import "HHImageCacheConfig.h"
  12 +
  13 +typedef NS_ENUM(NSInteger, HHImageCacheType) {
  14 + /**
  15 + * The image wasn't available the HHWebImage caches, but was downloaded from the web.
  16 + */
  17 + HHImageCacheTypeNone,
  18 + /**
  19 + * The image was obtained from the disk cache.
  20 + */
  21 + HHImageCacheTypeDisk,
  22 + /**
  23 + * The image was obtained from the memory cache.
  24 + */
  25 + HHImageCacheTypeMemory
  26 +};
  27 +
  28 +typedef NS_OPTIONS(NSUInteger, HHImageCacheOptions) {
  29 + /**
  30 + * By default, we do not query disk data when the image is cached in memory. This mask can force to query disk data at the same time.
  31 + */
  32 + HHImageCacheQueryDataWhenInMemory = 1 << 0,
  33 + /**
  34 + * By default, we query the memory cache synchronously, disk cache asynchronously. This mask can force to query disk cache synchronously.
  35 + */
  36 + HHImageCacheQueryDiskSync = 1 << 1
  37 +};
  38 +
  39 +typedef void(^HHCacheQueryCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, HHImageCacheType cacheType);
  40 +
  41 +typedef void(^HHWebImageCheckCacheCompletionBlock)(BOOL isInCache);
  42 +
  43 +typedef void(^HHWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize);
  44 +
  45 +
  46 +/**
  47 + * HHImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed
  48 + * asynchronous so it doesn’t add unnecessary latency to the UI.
  49 + */
  50 +@interface HHImageCache : NSObject
  51 +
  52 +#pragma mark - Properties
  53 +
  54 +/**
  55 + * Cache Config object - storing all kind of settings
  56 + */
  57 +@property (nonatomic, nonnull, readonly) HHImageCacheConfig *config;
  58 +
  59 +/**
  60 + * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.
  61 + */
  62 +@property (assign, nonatomic) NSUInteger maxMemoryCost;
  63 +
  64 +/**
  65 + * The maximum number of objects the cache should hold.
  66 + */
  67 +@property (assign, nonatomic) NSUInteger maxMemoryCountLimit;
  68 +
  69 +#pragma mark - Singleton and initialization
  70 +
  71 +/**
  72 + * Returns global shared cache instance
  73 + *
  74 + * @return HHImageCache global instance
  75 + */
  76 ++ (nonnull instancetype)sharedImageCache;
  77 +
  78 +/**
  79 + * Init a new cache store with a specific namespace
  80 + *
  81 + * @param ns The namespace to use for this cache store
  82 + */
  83 +- (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns;
  84 +
  85 +/**
  86 + * Init a new cache store with a specific namespace and directory
  87 + *
  88 + * @param ns The namespace to use for this cache store
  89 + * @param directory Directory to cache disk images in
  90 + */
  91 +- (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns
  92 + diskCacheDirectory:(nonnull NSString *)directory NS_DESIGNATED_INITIALIZER;
  93 +
  94 +#pragma mark - Cache paths
  95 +
  96 +- (nullable NSString *)makeDiskCachePath:(nonnull NSString*)fullNamespace;
  97 +
  98 +/**
  99 + * Add a read-only cache path to search for images pre-cached by HHImageCache
  100 + * Useful if you want to bundle pre-loaded images with your app
  101 + *
  102 + * @param path The path to use for this read-only cache path
  103 + */
  104 +- (void)addReadOnlyCachePath:(nonnull NSString *)path;
  105 +
  106 +#pragma mark - Store Ops
  107 +
  108 +/**
  109 + * Asynchronously store an image into memory and disk cache at the given key.
  110 + *
  111 + * @param image The image to store
  112 + * @param key The unique image cache key, usually it's image absolute URL
  113 + * @param completionBlock A block executed after the operation is finished
  114 + */
  115 +- (void)storeImage:(nullable UIImage *)image
  116 + forKey:(nullable NSString *)key
  117 + completion:(nullable HHWebImageNoParamsBlock)completionBlock;
  118 +
  119 +/**
  120 + * Asynchronously store an image into memory and disk cache at the given key.
  121 + *
  122 + * @param image The image to store
  123 + * @param key The unique image cache key, usually it's image absolute URL
  124 + * @param toDisk Store the image to disk cache if YES
  125 + * @param completionBlock A block executed after the operation is finished
  126 + */
  127 +- (void)storeImage:(nullable UIImage *)image
  128 + forKey:(nullable NSString *)key
  129 + toDisk:(BOOL)toDisk
  130 + completion:(nullable HHWebImageNoParamsBlock)completionBlock;
  131 +
  132 +/**
  133 + * Asynchronously store an image into memory and disk cache at the given key.
  134 + *
  135 + * @param image The image to store
  136 + * @param imageData The image data as returned by the server, this representation will be used for disk storage
  137 + * instead of converting the given image object into a storable/compressed image format in order
  138 + * to save quality and CPU
  139 + * @param key The unique image cache key, usually it's image absolute URL
  140 + * @param toDisk Store the image to disk cache if YES
  141 + * @param completionBlock A block executed after the operation is finished
  142 + */
  143 +- (void)storeImage:(nullable UIImage *)image
  144 + imageData:(nullable NSData *)imageData
  145 + forKey:(nullable NSString *)key
  146 + toDisk:(BOOL)toDisk
  147 + completion:(nullable HHWebImageNoParamsBlock)completionBlock;
  148 +
  149 +/**
  150 + * Synchronously store image NSData into disk cache at the given key.
  151 + *
  152 + * @warning This method is synchronous, make sure to call it from the ioQueue
  153 + *
  154 + * @param imageData The image data to store
  155 + * @param key The unique image cache key, usually it's image absolute URL
  156 + */
  157 +- (void)storeImageDataToDisk:(nullable NSData *)imageData forKey:(nullable NSString *)key;
  158 +
  159 +#pragma mark - Query and Retrieve Ops
  160 +
  161 +/**
  162 + * Async check if image exists in disk cache already (does not load the image)
  163 + *
  164 + * @param key the key describing the url
  165 + * @param completionBlock the block to be executed when the check is done.
  166 + * @note the completion block will be always executed on the main queue
  167 + */
  168 +- (void)diskImageExistsWithKey:(nullable NSString *)key completion:(nullable HHWebImageCheckCacheCompletionBlock)completionBlock;
  169 +
  170 +/**
  171 + * Sync check if image data exists in disk cache already (does not load the image)
  172 + *
  173 + * @param key the key describing the url
  174 + */
  175 +- (BOOL)diskImageDataExistsWithKey:(nullable NSString *)key;
  176 +
  177 +/**
  178 + * Operation that queries the cache asynchronously and call the completion when done.
  179 + *
  180 + * @param key The unique key used to store the wanted image
  181 + * @param doneBlock The completion block. Will not get called if the operation is cancelled
  182 + *
  183 + * @return a NSOperation instance containing the cache op
  184 + */
  185 +- (nullable NSOperation *)queryCacheOperationForKey:(nullable NSString *)key done:(nullable HHCacheQueryCompletedBlock)doneBlock;
  186 +
  187 +/**
  188 + * Operation that queries the cache asynchronously and call the completion when done.
  189 + *
  190 + * @param key The unique key used to store the wanted image
  191 + * @param options A mask to specify options to use for this cache query
  192 + * @param doneBlock The completion block. Will not get called if the operation is cancelled
  193 + *
  194 + * @return a NSOperation instance containing the cache op
  195 + */
  196 +- (nullable NSOperation *)queryCacheOperationForKey:(nullable NSString *)key options:(HHImageCacheOptions)options done:(nullable HHCacheQueryCompletedBlock)doneBlock;
  197 +
  198 +/**
  199 + * Query the memory cache synchronously.
  200 + *
  201 + * @param key The unique key used to store the image
  202 + */
  203 +- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key;
  204 +
  205 +/**
  206 + * Query the disk cache synchronously.
  207 + *
  208 + * @param key The unique key used to store the image
  209 + */
  210 +- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key;
  211 +
  212 +/**
  213 + * Query the cache (memory and or disk) synchronously after checking the memory cache.
  214 + *
  215 + * @param key The unique key used to store the image
  216 + */
  217 +- (nullable UIImage *)imageFromCacheForKey:(nullable NSString *)key;
  218 +
  219 +#pragma mark - Remove Ops
  220 +
  221 +/**
  222 + * Remove the image from memory and disk cache asynchronously
  223 + *
  224 + * @param key The unique image cache key
  225 + * @param completion A block that should be executed after the image has been removed (optional)
  226 + */
  227 +- (void)removeImageForKey:(nullable NSString *)key withCompletion:(nullable HHWebImageNoParamsBlock)completion;
  228 +
  229 +/**
  230 + * Remove the image from memory and optionally disk cache asynchronously
  231 + *
  232 + * @param key The unique image cache key
  233 + * @param fromDisk Also remove cache entry from disk if YES
  234 + * @param completion A block that should be executed after the image has been removed (optional)
  235 + */
  236 +- (void)removeImageForKey:(nullable NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(nullable HHWebImageNoParamsBlock)completion;
  237 +
  238 +#pragma mark - Cache clean Ops
  239 +
  240 +/**
  241 + * Clear all memory cached images
  242 + */
  243 +- (void)clearMemory;
  244 +
  245 +/**
  246 + * Async clear all disk cached images. Non-blocking method - returns immediately.
  247 + * @param completion A block that should be executed after cache expiration completes (optional)
  248 + */
  249 +- (void)clearDiskOnCompletion:(nullable HHWebImageNoParamsBlock)completion;
  250 +
  251 +/**
  252 + * Async remove all expired cached image from disk. Non-blocking method - returns immediately.
  253 + * @param completionBlock A block that should be executed after cache expiration completes (optional)
  254 + */
  255 +- (void)deleteOldFilesWithCompletionBlock:(nullable HHWebImageNoParamsBlock)completionBlock;
  256 +
  257 +#pragma mark - Cache Info
  258 +
  259 +/**
  260 + * Get the size used by the disk cache
  261 + */
  262 +- (NSUInteger)getSize;
  263 +
  264 +/**
  265 + * Get the number of images in the disk cache
  266 + */
  267 +- (NSUInteger)getDiskCount;
  268 +
  269 +/**
  270 + * Asynchronously calculate the disk cache's size.
  271 + */
  272 +- (void)calculateSizeWithCompletionBlock:(nullable HHWebImageCalculateSizeBlock)completionBlock;
  273 +
  274 +#pragma mark - Cache Paths
  275 +
  276 +/**
  277 + * Get the cache path for a certain key (needs the cache path root folder)
  278 + *
  279 + * @param key the key (can be obtained from url using cacheKeyForURL)
  280 + * @param path the cache path root folder
  281 + *
  282 + * @return the cache path
  283 + */
  284 +- (nullable NSString *)cachePathForKey:(nullable NSString *)key inPath:(nonnull NSString *)path;
  285 +
  286 +/**
  287 + * Get the default cache path for a certain key
  288 + *
  289 + * @param key the key (can be obtained from url using cacheKeyForURL)
  290 + *
  291 + * @return the default cache path
  292 + */
  293 +- (nullable NSString *)defaultCachePathForKey:(nullable NSString *)key;
  294 +
  295 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageCompat.h"
  11 +
  12 +@interface HHImageCacheConfig : NSObject
  13 +
  14 +/**
  15 + * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory.
  16 + * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
  17 + */
  18 +@property (assign, nonatomic) BOOL shouldDecompressImages;
  19 +
  20 +/**
  21 + * disable iCloud backup [defaults to YES]
  22 + */
  23 +@property (assign, nonatomic) BOOL shouldDisableiCloud;
  24 +
  25 +/**
  26 + * use memory cache [defaults to YES]
  27 + */
  28 +@property (assign, nonatomic) BOOL shouldCacheImagesInMemory;
  29 +
  30 +/**
  31 + * The reading options while reading cache from disk.
  32 + * Defaults to 0. You can set this to `NHHataReadingMappedIfSafe` to improve performance.
  33 + */
  34 +@property (assign, nonatomic) NSDataReadingOptions diskCacheReadingOptions;
  35 +
  36 +/**
  37 + * The writing options while writing cache to disk.
  38 + * Defaults to `NSDataWritingAtomic`. You can set this to `NSDataWritingWithoutOverwriting` to prevent overwriting an existing file.
  39 + */
  40 +@property (assign, nonatomic) NSDataWritingOptions diskCacheWritingOptions;
  41 +
  42 +/**
  43 + * The maximum length of time to keep an image in the cache, in seconds.
  44 + */
  45 +@property (assign, nonatomic) NSInteger maxCacheAge;
  46 +
  47 +/**
  48 + * The maximum size of the cache, in bytes.
  49 + */
  50 +@property (assign, nonatomic) NSUInteger maxCacheSize;
  51 +
  52 +@end
  1 +//
  2 +// MBProgressHUD.h
  3 +// Version 1.1.0
  4 +// Created by Matej Bukovinski on 2.4.09.
  5 +//
  6 +
  7 +// This code is distributed under the terms and conditions of the MIT license.
  8 +
  9 +// Copyright © 2009-2016 Matej Bukovinski
  10 +//
  11 +// Permission is hereby granted, free of charge, to any person obtaining a copy
  12 +// of this software and associated documentation files (the "Software"), to deal
  13 +// in the Software without restriction, including without limitation the rights
  14 +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15 +// copies of the Software, and to permit persons to whom the Software is
  16 +// furnished to do so, subject to the following conditions:
  17 +//
  18 +// The above copyright notice and this permission notice shall be included in
  19 +// all copies or substantial portions of the Software.
  20 +//
  21 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22 +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23 +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24 +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25 +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26 +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27 +// THE SOFTWARE.
  28 +
  29 +#import <Foundation/Foundation.h>
  30 +#import <UIKit/UIKit.h>
  31 +#import <CoreGraphics/CoreGraphics.h>
  32 +
  33 +@class HH_MBBackgroundView;
  34 +@protocol HH_MBProgressHUDDelegate;
  35 +
  36 +
  37 +extern CGFloat const HH_MBProgressMaxOffset;
  38 +
  39 +typedef NS_ENUM(NSInteger, HH_MBProgressHUDMode) {
  40 + /// UIActivityIndicatorView.
  41 + MBProgressHUDModeIndeterminate,
  42 + /// A round, pie-chart like, progress view.
  43 + MBProgressHUDModeDeterminate,
  44 + /// Horizontal progress bar.
  45 + MBProgressHUDModeDeterminateHorizontalBar,
  46 + /// Ring-shaped progress view.
  47 + MBProgressHUDModeAnnularDeterminate,
  48 + /// Shows a custom view.
  49 + MBProgressHUDModeCustomView,
  50 + /// Shows only labels.
  51 + MBProgressHUDModeText
  52 +};
  53 +
  54 +typedef NS_ENUM(NSInteger, HH_MBProgressHUDAnimation) {
  55 + /// Opacity animation
  56 + MBProgressHUDAnimationFade,
  57 + /// Opacity + scale animation (zoom in when appearing zoom out when disappearing)
  58 + MBProgressHUDAnimationZoom,
  59 + /// Opacity + scale animation (zoom out style)
  60 + MBProgressHUDAnimationZoomOut,
  61 + /// Opacity + scale animation (zoom in style)
  62 + MBProgressHUDAnimationZoomIn
  63 +};
  64 +
  65 +typedef NS_ENUM(NSInteger, HH_MBProgressHUDBackgroundStyle) {
  66 + /// Solid color background
  67 + MBProgressHUDBackgroundStyleSolidColor,
  68 + /// UIVisualEffectView or UIToolbar.layer background view
  69 + MBProgressHUDBackgroundStyleBlur
  70 +};
  71 +
  72 +typedef void (^HH_MBProgressHUDCompletionBlock)(void);
  73 +
  74 +
  75 +NS_ASSUME_NONNULL_BEGIN
  76 +
  77 +
  78 +/**
  79 + * Displays a simple HUD window containing a progress indicator and two optional labels for short messages.
  80 + *
  81 + * This is a simple drop-in class for displaying a progress HUD view similar to Apple's private UIProgressHUD class.
  82 + * The MBProgressHUD window spans over the entire space given to it by the initWithFrame: constructor and catches all
  83 + * user input on this region, thereby preventing the user operations on components below the view.
  84 + *
  85 + * @note To still allow touches to pass through the HUD, you can set hud.userInteractionEnabled = NO.
  86 + * @attention MBProgressHUD is a UI class and should therefore only be accessed on the main thread.
  87 + */
  88 +@interface HH_MBProgressHUD : UIView
  89 +
  90 +/**
  91 + * Creates a new HUD, adds it to provided view and shows it. The counterpart to this method is hideHUDForView:animated:.
  92 + *
  93 + * @note This method sets removeFromSuperViewOnHide. The HUD will automatically be removed from the view hierarchy when hidden.
  94 + *
  95 + * @param view The view that the HUD will be added to
  96 + * @param animated If set to YES the HUD will appear using the current animationType. If set to NO the HUD will not use
  97 + * animations while appearing.
  98 + * @return A reference to the created HUD.
  99 + *
  100 + * @see hideHUDForView:animated:
  101 + * @see animationType
  102 + */
  103 ++ (instancetype)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;
  104 +
  105 +/// @name Showing and hiding
  106 +
  107 +/**
  108 + * Finds the top-most HUD subview that hasn't finished and hides it. The counterpart to this method is showHUDAddedTo:animated:.
  109 + *
  110 + * @note This method sets removeFromSuperViewOnHide. The HUD will automatically be removed from the view hierarchy when hidden.
  111 + *
  112 + * @param view The view that is going to be searched for a HUD subview.
  113 + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use
  114 + * animations while disappearing.
  115 + * @return YES if a HUD was found and removed, NO otherwise.
  116 + *
  117 + * @see showHUDAddedTo:animated:
  118 + * @see animationType
  119 + */
  120 ++ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated;
  121 +
  122 +/**
  123 + * Finds the top-most HUD subview that hasn't finished and returns it.
  124 + *
  125 + * @param view The view that is going to be searched.
  126 + * @return A reference to the last HUD subview discovered.
  127 + */
  128 ++ (nullable HH_MBProgressHUD *)HUDForView:(UIView *)view;
  129 +
  130 +/**
  131 + * A convenience constructor that initializes the HUD with the view's bounds. Calls the designated constructor with
  132 + * view.bounds as the parameter.
  133 + *
  134 + * @param view The view instance that will provide the bounds for the HUD. Should be the same instance as
  135 + * the HUD's superview (i.e., the view that the HUD will be added to).
  136 + */
  137 +- (instancetype)initWithView:(UIView *)view;
  138 +
  139 +/**
  140 + * Displays the HUD.
  141 + *
  142 + * @note You need to make sure that the main thread completes its run loop soon after this method call so that
  143 + * the user interface can be updated. Call this method when your task is already set up to be executed in a new thread
  144 + * (e.g., when using something like NSOperation or making an asynchronous call like NSURLRequest).
  145 + *
  146 + * @param animated If set to YES the HUD will appear using the current animationType. If set to NO the HUD will not use
  147 + * animations while appearing.
  148 + *
  149 + * @see animationType
  150 + */
  151 +- (void)showAnimated:(BOOL)animated;
  152 +
  153 +/**
  154 + * Hides the HUD. This still calls the hudWasHidden: delegate. This is the counterpart of the show: method. Use it to
  155 + * hide the HUD when your task completes.
  156 + *
  157 + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use
  158 + * animations while disappearing.
  159 + *
  160 + * @see animationType
  161 + */
  162 +- (void)hideAnimated:(BOOL)animated;
  163 +
  164 +/**
  165 + * Hides the HUD after a delay. This still calls the hudWasHidden: delegate. This is the counterpart of the show: method. Use it to
  166 + * hide the HUD when your task completes.
  167 + *
  168 + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use
  169 + * animations while disappearing.
  170 + * @param delay Delay in seconds until the HUD is hidden.
  171 + *
  172 + * @see animationType
  173 + */
  174 +- (void)hideAnimated:(BOOL)animated afterDelay:(NSTimeInterval)delay;
  175 +
  176 +/**
  177 + * The HUD delegate object. Receives HUD state notifications.
  178 + */
  179 +@property (weak, nonatomic) id<HH_MBProgressHUDDelegate> delegate;
  180 +
  181 +/**
  182 + * Called after the HUD is hiden.
  183 + */
  184 +@property (copy, nullable) HH_MBProgressHUDCompletionBlock completionBlock;
  185 +
  186 +/*
  187 + * Grace period is the time (in seconds) that the invoked method may be run without
  188 + * showing the HUD. If the task finishes before the grace time runs out, the HUD will
  189 + * not be shown at all.
  190 + * This may be used to prevent HUD display for very short tasks.
  191 + * Defaults to 0 (no grace time).
  192 + */
  193 +@property (assign, nonatomic) NSTimeInterval graceTime;
  194 +
  195 +/**
  196 + * The minimum time (in seconds) that the HUD is shown.
  197 + * This avoids the problem of the HUD being shown and than instantly hidden.
  198 + * Defaults to 0 (no minimum show time).
  199 + */
  200 +@property (assign, nonatomic) NSTimeInterval minShowTime;
  201 +
  202 +/**
  203 + * Removes the HUD from its parent view when hidden.
  204 + * Defaults to NO.
  205 + */
  206 +@property (assign, nonatomic) BOOL removeFromSuperViewOnHide;
  207 +
  208 +/// @name Appearance
  209 +
  210 +/**
  211 + * MBProgressHUD operation mode. The default is MBProgressHUDModeIndeterminate.
  212 + */
  213 +@property (assign, nonatomic) HH_MBProgressHUDMode mode;
  214 +
  215 +/**
  216 + * A color that gets forwarded to all labels and supported indicators. Also sets the tintColor
  217 + * for custom views on iOS 7+. Set to nil to manage color individually.
  218 + * Defaults to semi-translucent black on iOS 7 and later and white on earlier iOS versions.
  219 + */
  220 +@property (strong, nonatomic, nullable) UIColor *contentColor UI_APPEARANCE_SELECTOR;
  221 +
  222 +/**
  223 + * The animation type that should be used when the HUD is shown and hidden.
  224 + */
  225 +@property (assign, nonatomic) HH_MBProgressHUDAnimation animationType UI_APPEARANCE_SELECTOR;
  226 +
  227 +/**
  228 + * The bezel offset relative to the center of the view. You can use MBProgressMaxOffset
  229 + * and -MBProgressMaxOffset to move the HUD all the way to the screen edge in each direction.
  230 + * E.g., CGPointMake(0.f, MBProgressMaxOffset) would position the HUD centered on the bottom edge.
  231 + */
  232 +@property (assign, nonatomic) CGPoint offset UI_APPEARANCE_SELECTOR;
  233 +
  234 +/**
  235 + * The amount of space between the HUD edge and the HUD elements (labels, indicators or custom views).
  236 + * This also represents the minimum bezel distance to the edge of the HUD view.
  237 + * Defaults to 20.f
  238 + */
  239 +@property (assign, nonatomic) CGFloat margin UI_APPEARANCE_SELECTOR;
  240 +
  241 +/**
  242 + * The minimum size of the HUD bezel. Defaults to CGSizeZero (no minimum size).
  243 + */
  244 +@property (assign, nonatomic) CGSize minSize UI_APPEARANCE_SELECTOR;
  245 +
  246 +/**
  247 + * Force the HUD dimensions to be equal if possible.
  248 + */
  249 +@property (assign, nonatomic, getter = isSquare) BOOL square UI_APPEARANCE_SELECTOR;
  250 +
  251 +/**
  252 + * When enabled, the bezel center gets slightly affected by the device accelerometer data.
  253 + * Has no effect on iOS < 7.0. Defaults to YES.
  254 + */
  255 +@property (assign, nonatomic, getter=areDefaultMotionEffectsEnabled) BOOL defaultMotionEffectsEnabled UI_APPEARANCE_SELECTOR;
  256 +
  257 +/// @name Progress
  258 +
  259 +/**
  260 + * The progress of the progress indicator, from 0.0 to 1.0. Defaults to 0.0.
  261 + */
  262 +@property (assign, nonatomic) float progress;
  263 +
  264 +/// @name ProgressObject
  265 +
  266 +/**
  267 + * The NSProgress object feeding the progress information to the progress indicator.
  268 + */
  269 +@property (strong, nonatomic, nullable) NSProgress *progressObject;
  270 +
  271 +/// @name Views
  272 +
  273 +/**
  274 + * The view containing the labels and indicator (or customView).
  275 + */
  276 +@property (strong, nonatomic, readonly) HH_MBBackgroundView *bezelView;
  277 +
  278 +/**
  279 + * View covering the entire HUD area, placed behind bezelView.
  280 + */
  281 +@property (strong, nonatomic, readonly) HH_MBBackgroundView *backgroundView;
  282 +
  283 +/**
  284 + * The UIView (e.g., a UIImageView) to be shown when the HUD is in MBProgressHUDModeCustomView.
  285 + * The view should implement intrinsicContentSize for proper sizing. For best results use approximately 37 by 37 pixels.
  286 + */
  287 +@property (strong, nonatomic, nullable) UIView *customView;
  288 +
  289 +/**
  290 + * A label that holds an optional short message to be displayed below the activity indicator. The HUD is automatically resized to fit
  291 + * the entire text.
  292 + */
  293 +@property (strong, nonatomic, readonly) UILabel *label;
  294 +
  295 +/**
  296 + * A label that holds an optional details message displayed below the labelText message. The details text can span multiple lines.
  297 + */
  298 +@property (strong, nonatomic, readonly) UILabel *detailsLabel;
  299 +
  300 +/**
  301 + * A button that is placed below the labels. Visible only if a target / action is added.
  302 + */
  303 +//@property (strong, nonatomic, readonly) UIButton *button;
  304 +
  305 +@end
  306 +
  307 +
  308 +@protocol HH_MBProgressHUDDelegate <NSObject>
  309 +
  310 +@optional
  311 +
  312 +/**
  313 + * Called after the HUD was fully hidden from the screen.
  314 + */
  315 +- (void)hudWasHidden:(HH_MBProgressHUD *)hud;
  316 +
  317 +@end
  318 +
  319 +
  320 +/**
  321 + * A progress view for showing definite progress by filling up a circle (pie chart).
  322 + */
  323 +@interface HH_MBRoundProgressView : UIView
  324 +
  325 +/**
  326 + * Progress (0.0 to 1.0)
  327 + */
  328 +@property (nonatomic, assign) float progress;
  329 +
  330 +/**
  331 + * Indicator progress color.
  332 + * Defaults to white [UIColor whiteColor].
  333 + */
  334 +@property (nonatomic, strong) UIColor *progressTintColor;
  335 +
  336 +/**
  337 + * Indicator background (non-progress) color.
  338 + * Only applicable on iOS versions older than iOS 7.
  339 + * Defaults to translucent white (alpha 0.1).
  340 + */
  341 +@property (nonatomic, strong) UIColor *backgroundTintColor;
  342 +
  343 +/*
  344 + * Display mode - NO = round or YES = annular. Defaults to round.
  345 + */
  346 +@property (nonatomic, assign, getter = isAnnular) BOOL annular;
  347 +
  348 +@end
  349 +
  350 +
  351 +/**
  352 + * A flat bar progress view.
  353 + */
  354 +@interface HH_MBBarProgressView : UIView
  355 +
  356 +/**
  357 + * Progress (0.0 to 1.0)
  358 + */
  359 +@property (nonatomic, assign) float progress;
  360 +
  361 +/**
  362 + * Bar border line color.
  363 + * Defaults to white [UIColor whiteColor].
  364 + */
  365 +@property (nonatomic, strong) UIColor *lineColor;
  366 +
  367 +/**
  368 + * Bar background color.
  369 + * Defaults to clear [UIColor clearColor];
  370 + */
  371 +@property (nonatomic, strong) UIColor *progressRemainingColor;
  372 +
  373 +/**
  374 + * Bar progress color.
  375 + * Defaults to white [UIColor whiteColor].
  376 + */
  377 +@property (nonatomic, strong) UIColor *progressColor;
  378 +
  379 +@end
  380 +
  381 +
  382 +@interface HH_MBBackgroundView : UIView
  383 +
  384 +/**
  385 + * The background style.
  386 + * Defaults to MBProgressHUDBackgroundStyleBlur on iOS 7 or later and MBProgressHUDBackgroundStyleSolidColor otherwise.
  387 + * @note Due to iOS 7 not supporting UIVisualEffectView, the blur effect differs slightly between iOS 7 and later versions.
  388 + */
  389 +@property (nonatomic) HH_MBProgressHUDBackgroundStyle style;
  390 +
  391 +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV
  392 +/**
  393 + * The blur effect style, when using MBProgressHUDBackgroundStyleBlur.
  394 + * Defaults to UIBlurEffectStyleLight.
  395 + */
  396 +@property (nonatomic) UIBlurEffectStyle blurEffectStyle;
  397 +#endif
  398 +
  399 +/**
  400 + * The background color or the blur tint color.
  401 + * @note Due to iOS 7 not supporting UIVisualEffectView, the blur effect differs slightly between iOS 7 and later versions.
  402 + */
  403 +@property (nonatomic, strong) UIColor *color;
  404 +
  405 +@end
  406 +
  407 +
  408 +@interface HH_MBProgressHUD (Deprecated)
  409 +
  410 ++ (NSArray *)allHUDsForView:(UIView *)view __attribute__((deprecated("Store references when using more than one HUD per view.")));
  411 ++ (NSUInteger)hideAllHUDsForView:(UIView *)view animated:(BOOL)animated __attribute__((deprecated("Store references when using more than one HUD per view.")));
  412 +
  413 +- (id)initWithWindow:(UIWindow *)window __attribute__((deprecated("Use initWithView: instead.")));
  414 +
  415 +- (void)show:(BOOL)animated __attribute__((deprecated("Use showAnimated: instead.")));
  416 +- (void)hide:(BOOL)animated __attribute__((deprecated("Use hideAnimated: instead.")));
  417 +- (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay __attribute__((deprecated("Use hideAnimated:afterDelay: instead.")));
  418 +
  419 +- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated __attribute__((deprecated("Use GCD directly.")));
  420 +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block __attribute__((deprecated("Use GCD directly.")));
  421 +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(nullable HH_MBProgressHUDCompletionBlock)completion __attribute__((deprecated("Use GCD directly.")));
  422 +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue __attribute__((deprecated("Use GCD directly.")));
  423 +- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue
  424 + completionBlock:(nullable HH_MBProgressHUDCompletionBlock)completion __attribute__((deprecated("Use GCD directly.")));
  425 +@property (assign) BOOL taskInProgress __attribute__((deprecated("No longer needed.")));
  426 +
  427 +@property (nonatomic, copy) NSString *labelText __attribute__((deprecated("Use label.text instead.")));
  428 +@property (nonatomic, strong) UIFont *labelFont __attribute__((deprecated("Use label.font instead.")));
  429 +@property (nonatomic, strong) UIColor *labelColor __attribute__((deprecated("Use label.textColor instead.")));
  430 +@property (nonatomic, copy) NSString *detailsLabelText __attribute__((deprecated("Use detailsLabel.text instead.")));
  431 +@property (nonatomic, strong) UIFont *detailsLabelFont __attribute__((deprecated("Use detailsLabel.font instead.")));
  432 +@property (nonatomic, strong) UIColor *detailsLabelColor __attribute__((deprecated("Use detailsLabel.textColor instead.")));
  433 +@property (assign, nonatomic) CGFloat opacity __attribute__((deprecated("Customize bezelView properties instead.")));
  434 +@property (strong, nonatomic) UIColor *color __attribute__((deprecated("Customize the bezelView color instead.")));
  435 +@property (assign, nonatomic) CGFloat xOffset __attribute__((deprecated("Set offset.x instead.")));
  436 +@property (assign, nonatomic) CGFloat yOffset __attribute__((deprecated("Set offset.y instead.")));
  437 +@property (assign, nonatomic) CGFloat cornerRadius __attribute__((deprecated("Set bezelView.layer.cornerRadius instead.")));
  438 +@property (assign, nonatomic) BOOL dimBackground __attribute__((deprecated("Customize HUD background properties instead.")));
  439 +@property (strong, nonatomic) UIColor *activityIndicatorColor __attribute__((deprecated("Use UIAppearance to customize UIActivityIndicatorView. E.g.: [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = [UIColor redColor];")));
  440 +@property (atomic, assign, readonly) CGSize size __attribute__((deprecated("Get the bezelView.frame.size instead.")));
  441 +
  442 +@end
  443 +
  444 +NS_ASSUME_NONNULL_END
@@ -10,6 +10,35 @@ @@ -10,6 +10,35 @@
10 #endif 10 #endif
11 #endif 11 #endif
12 12
  13 +#import "HHMBProgressHUD.h"
  14 +#import "HttpsDNSAuth.h"
  15 +#import "ObjectMapper.h"
  16 +#import "HHAnimatedImageRep.h"
  17 +#import "HHImageCache.h"
  18 +#import "HHImageCacheConfig.h"
  19 +#import "HHWebImageCoder.h"
  20 +#import "HHWebImageCoderHelper.h"
  21 +#import "HHWebImageCodersManager.h"
  22 +#import "HHWebImageCompat.h"
  23 +#import "HHWebImageDownloader.h"
  24 +#import "HHWebImageDownloaderOperation.h"
  25 +#import "HHWebImageFrame.h"
  26 +#import "HHWebImageGIFCoder.h"
  27 +#import "HHWebImageImageIOCoder.h"
  28 +#import "HHWebImageManager.h"
  29 +#import "HHWebImageOperation.h"
  30 +#import "HHWebImagePrefetcher.h"
  31 +#import "HHWebImageTransition.h"
  32 +#import "NSData+hhImageContentType.h"
  33 +#import "NSImage+hhWebCache.h"
  34 +#import "UIButton+hhWebCache.h"
  35 +#import "UIImage+hhForceDecode.h"
  36 +#import "UIImage+hhGIF.h"
  37 +#import "UIImage+hhMultiFormat.h"
  38 +#import "UIImageView+hhHighlightedWebCache.h"
  39 +#import "UIImageView+hhWebCache.h"
  40 +#import "UIView+hhWebCache.h"
  41 +#import "UIView+hhWebCacheOperation.h"
13 42
14 FOUNDATION_EXPORT double HHSDKBaseVersionNumber; 43 FOUNDATION_EXPORT double HHSDKBaseVersionNumber;
15 FOUNDATION_EXPORT const unsigned char HHSDKBaseVersionString[]; 44 FOUNDATION_EXPORT const unsigned char HHSDKBaseVersionString[];
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageCompat.h"
  11 +#import "NSData+hhImageContentType.h"
  12 +
  13 +/**
  14 + A Boolean value indicating whether to scale down large images during decompressing. (NSNumber)
  15 + */
  16 +FOUNDATION_EXPORT NSString * _Nonnull const HHWebImageCoderScaleDownLargeImagesKey;
  17 +
  18 +/**
  19 + Return the shared device-dependent RGB color space created with CGColorSpaceCreateDeviceRGB.
  20 +
  21 + @return The device-dependent RGB color space
  22 + */
  23 +CG_EXTERN CGColorSpaceRef _Nonnull HHCGColorSpaceGetDeviceRGB(void);
  24 +
  25 +/**
  26 + Check whether CGImageRef contains alpha channel.
  27 +
  28 + @param imageRef The CGImageRef
  29 + @return Return YES if CGImageRef contains alpha channel, otherwise return NO
  30 + */
  31 +CG_EXTERN BOOL HHCGImageRefContainsAlpha(_Nullable CGImageRef imageRef);
  32 +
  33 +
  34 +/**
  35 + This is the image coder protocol to provide custom image decoding/encoding.
  36 + These methods are all required to implement.
  37 + @note Pay attention that these methods are not called from main queue.
  38 + */
  39 +@protocol HHWebImageCoder <NSObject>
  40 +
  41 +@required
  42 +#pragma mark - Decoding
  43 +/**
  44 + Returns YES if this coder can decode some data. Otherwise, the data should be passed to another coder.
  45 +
  46 + @param data The image data so we can look at it
  47 + @return YES if this coder can decode the data, NO otherwise
  48 + */
  49 +- (BOOL)canDecodeFromData:(nullable NSData *)data;
  50 +
  51 +/**
  52 + Decode the image data to image.
  53 +
  54 + @param data The image data to be decoded
  55 + @return The decoded image from data
  56 + */
  57 +- (nullable UIImage *)decodedImageWithData:(nullable NSData *)data;
  58 +
  59 +/**
  60 + Decompress the image with original image and image data.
  61 +
  62 + @param image The original image to be decompressed
  63 + @param data The pointer to original image data. The pointer itself is nonnull but image data can be null. This data will set to cache if needed. If you do not need to modify data at the sametime, ignore this param.
  64 + @param optionsDict A dictionary containing any decompressing options. Pass {HHWebImageCoderScaleDownLargeImagesKey: @(YES)} to scale down large images
  65 + @return The decompressed image
  66 + */
  67 +- (nullable UIImage *)decompressedImageWithImage:(nullable UIImage *)image
  68 + data:(NSData * _Nullable * _Nonnull)data
  69 + options:(nullable NSDictionary<NSString*, NSObject*>*)optionsDict;
  70 +
  71 +#pragma mark - Encoding
  72 +
  73 +/**
  74 + Returns YES if this coder can encode some image. Otherwise, it should be passed to another coder.
  75 +
  76 + @param format The image format
  77 + @return YES if this coder can encode the image, NO otherwise
  78 + */
  79 +- (BOOL)canEncodeToFormat:(HHImageFormat)format;
  80 +
  81 +/**
  82 + Encode the image to image data.
  83 +
  84 + @param image The image to be encoded
  85 + @param format The image format to encode, you should note `HHImageFormatUndefined` format is also possible
  86 + @return The encoded image data
  87 + */
  88 +- (nullable NSData *)encodedDataWithImage:(nullable UIImage *)image format:(HHImageFormat)format;
  89 +
  90 +@end
  91 +
  92 +
  93 +/**
  94 + This is the image coder protocol to provide custom progressive image decoding.
  95 + These methods are all required to implement.
  96 + @note Pay attention that these methods are not called from main queue.
  97 + */
  98 +@protocol HHWebImageProgressiveCoder <HHWebImageCoder>
  99 +
  100 +@required
  101 +/**
  102 + Returns YES if this coder can incremental decode some data. Otherwise, it should be passed to another coder.
  103 +
  104 + @param data The image data so we can look at it
  105 + @return YES if this coder can decode the data, NO otherwise
  106 + */
  107 +- (BOOL)canIncrementallyDecodeFromData:(nullable NSData *)data;
  108 +
  109 +/**
  110 + Incremental decode the image data to image.
  111 +
  112 + @param data The image data has been downloaded so far
  113 + @param finished Whether the download has finished
  114 + @warning because incremental decoding need to keep the decoded context, we will alloc a new instance with the same class for each download operation to avoid conflicts
  115 + @return The decoded image from data
  116 + */
  117 +- (nullable UIImage *)incrementallyDecodedImageWithData:(nullable NSData *)data finished:(BOOL)finished;
  118 +
  119 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageCompat.h"
  11 +#import "HHWebImageFrame.h"
  12 +
  13 +@interface HHWebImageCoderHelper : NSObject
  14 +
  15 +/**
  16 + Return an animated image with frames array.
  17 + For UIKit, this will apply the patch and then create animated UIImage. The patch is because that `+[UIImage animatedImageWithImages:duration:]` just use the average of duration for each image. So it will not work if different frame has different duration. Therefore we repeat the specify frame for specify times to let it work.
  18 + For AppKit, NSImage does not support animates other than GIF. This will try to encode the frames to GIF format and then create an animated NSImage for rendering. Attention the animated image may loss some detail if the input frames contain full alpha channel because GIF only supports 1 bit alpha channel. (For 1 pixel, either transparent or not)
  19 +
  20 + @param frames The frames array. If no frames or frames is empty, return nil
  21 + @return A animated image for rendering on UIImageView(UIKit) or NSImageView(AppKit)
  22 + */
  23 ++ (UIImage * _Nullable)animatedImageWithFrames:(NSArray<HHWebImageFrame *> * _Nullable)frames;
  24 +
  25 +/**
  26 + Return frames array from an animated image.
  27 + For UIKit, this will unapply the patch for the description above and then create frames array. This will also work for normal animated UIImage.
  28 + For AppKit, NSImage does not support animates other than GIF. This will try to decode the GIF imageRep and then create frames array.
  29 +
  30 + @param animatedImage A animated image. If it's not animated, return nil
  31 + @return The frames array
  32 + */
  33 ++ (NSArray<HHWebImageFrame *> * _Nullable)framesFromAnimatedImage:(UIImage * _Nullable)animatedImage;
  34 +
  35 +#if HH_UIKIT || HH_WATCH
  36 +/**
  37 + Convert an EXIF image orientation to an iOS one.
  38 +
  39 + @param exifOrientation EXIF orientation
  40 + @return iOS orientation
  41 + */
  42 ++ (UIImageOrientation)imageOrientationFromEXIFOrientation:(NSInteger)exifOrientation;
  43 +/**
  44 + Convert an iOS orientation to an EXIF image orientation.
  45 +
  46 + @param imageOrientation iOS orientation
  47 + @return EXIF orientation
  48 + */
  49 ++ (NSInteger)exifOrientationFromImageOrientation:(UIImageOrientation)imageOrientation;
  50 +#endif
  51 +
  52 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageCoder.h"
  11 +
  12 +/**
  13 + Global object holding the array of coders, so that we avoid passing them from object to object.
  14 + Uses a priority queue behind scenes, which means the latest added coders have the highest priority.
  15 + This is done so when encoding/decoding something, we go through the list and ask each coder if they can handle the current data.
  16 + That way, users can add their custom coders while preserving our existing prebuilt ones
  17 +
  18 + Note: the `coders` getter will return the coders in their reversed order
  19 + Example:
  20 + - by default we internally set coders = `IOCoder`, `WebPCoder`. (`GIFCoder` is not recommended to add only if you want to get GIF support without `FLAnimatedImage`)
  21 + - calling `coders` will return `@[WebPCoder, IOCoder]`
  22 + - call `[addCoder:[MyCrazyCoder new]]`
  23 + - calling `coders` now returns `@[MyCrazyCoder, WebPCoder, IOCoder]`
  24 +
  25 + Coders
  26 + ------
  27 + A coder must conform to the `HHWebImageCoder` protocol or even to `HHWebImageProgressiveCoder` if it supports progressive decoding
  28 + Conformance is important because that way, they will implement `canDecodeFromData` or `canEncodeToFormat`
  29 + Those methods are called on each coder in the array (using the priority order) until one of them returns YES.
  30 + That means that coder can decode that data / encode to that format
  31 + */
  32 +@interface HHWebImageCodersManager : NSObject<HHWebImageCoder>
  33 +
  34 +/**
  35 + Shared reusable instance
  36 + */
  37 ++ (nonnull instancetype)sharedInstance;
  38 +
  39 +/**
  40 + All coders in coders manager. The coders array is a priority queue, which means the later added coder will have the highest priority
  41 + */
  42 +@property (nonatomic, strong, readwrite, nullable) NSArray<HHWebImageCoder>* coders;
  43 +
  44 +/**
  45 + Add a new coder to the end of coders array. Which has the highest priority.
  46 +
  47 + @param coder coder
  48 + */
  49 +- (void)addCoder:(nonnull id<HHWebImageCoder>)coder;
  50 +
  51 +/**
  52 + Remove a coder in the coders array.
  53 +
  54 + @param coder coder
  55 + */
  56 +- (void)removeCoder:(nonnull id<HHWebImageCoder>)coder;
  57 +
  58 +@end
  1 +/*
  2 + * This file is part of the HHWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + * (c) Jamie Pinkham
  5 + *
  6 + * For the full copyright and license information, please view the LICENSE
  7 + * file that was distributed with this source code.
  8 + */
  9 +
  10 +#import <TargetConditionals.h>
  11 +
  12 +#ifdef __OBJC_GC__
  13 + #error HHWebImage does not support Objective-C Garbage Collection
  14 +#endif
  15 +
  16 +// Apple's defines from TargetConditionals.h are a bit weird.
  17 +// Seems like TARGET_OS_MAC is always defined (on all platforms).
  18 +// To determine if we are running on OSX, we can only rely on TARGET_OS_IPHONE=0 and all the other platforms
  19 +#if !TARGET_OS_IPHONE && !TARGET_OS_IOS && !TARGET_OS_TV && !TARGET_OS_WATCH
  20 + #define HH_MAC 1
  21 +#else
  22 + #define HH_MAC 0
  23 +#endif
  24 +
  25 +// iOS and tvOS are very similar, UIKit exists on both platforms
  26 +// Note: watchOS also has UIKit, but it's very limited
  27 +#if TARGET_OS_IOS || TARGET_OS_TV
  28 + #define HH_UIKIT 1
  29 +#else
  30 + #define HH_UIKIT 0
  31 +#endif
  32 +
  33 +#if TARGET_OS_IOS
  34 + #define HH_IOS 1
  35 +#else
  36 + #define HH_IOS 0
  37 +#endif
  38 +
  39 +#if TARGET_OS_TV
  40 + #define HH_TV 1
  41 +#else
  42 + #define HH_TV 0
  43 +#endif
  44 +
  45 +#if TARGET_OS_WATCH
  46 + #define HH_WATCH 1
  47 +#else
  48 + #define HH_WATCH 0
  49 +#endif
  50 +
  51 +
  52 +#if HH_MAC
  53 + #import <AppKit/AppKit.h>
  54 + #ifndef UIImage
  55 + #define UIImage NSImage
  56 + #endif
  57 + #ifndef UIImageView
  58 + #define UIImageView NSImageView
  59 + #endif
  60 + #ifndef UIView
  61 + #define UIView NSView
  62 + #endif
  63 +#else
  64 + #if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
  65 + #error HHWebImage doesn't support Deployment Target version < 5.0
  66 + #endif
  67 +
  68 + #if HH_UIKIT
  69 + #import <UIKit/UIKit.h>
  70 + #endif
  71 + #if HH_WATCH
  72 + #import <WatchKit/WatchKit.h>
  73 + #endif
  74 +#endif
  75 +
  76 +#ifndef NS_ENUM
  77 +#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
  78 +#endif
  79 +
  80 +#ifndef NS_OPTIONS
  81 +#define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
  82 +#endif
  83 +
  84 +FOUNDATION_EXPORT UIImage *HHScaledImageForKey(NSString *key, UIImage *image);
  85 +
  86 +typedef void(^HHWebImageNoParamsBlock)(void);
  87 +
  88 +FOUNDATION_EXPORT NSString *const HHWebImageErrorDomain;
  89 +
  90 +#ifndef dispatch_queue_async_safe
  91 +#define dispatch_queue_async_safe(queue, block)\
  92 + if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(queue)) == 0) {\
  93 + block();\
  94 + } else {\
  95 + dispatch_async(queue, block);\
  96 + }
  97 +#endif
  98 +
  99 +#ifndef dispatch_main_async_safe
  100 +#define dispatch_main_async_safe(block) dispatch_queue_async_safe(dispatch_get_main_queue(), block)
  101 +#endif
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageCompat.h"
  11 +#import "HHWebImageOperation.h"
  12 +
  13 +typedef NS_OPTIONS(NSUInteger, HHWebImageDownloaderOptions) {
  14 + /**
  15 + * Put the download in the low queue priority and task priority.
  16 + */
  17 + HHWebImageDownloaderLowPriority = 1 << 0,
  18 +
  19 + /**
  20 + * This flag enables progressive download, the image is displayed progressively during download as a browser would do.
  21 + */
  22 + HHWebImageDownloaderProgressiveDownload = 1 << 1,
  23 +
  24 + /**
  25 + * By default, request prevent the use of NSURLCache. With this flag, NSURLCache
  26 + * is used with default policies.
  27 + */
  28 + HHWebImageDownloaderUseNSURLCache = 1 << 2,
  29 +
  30 + /**
  31 + * Call completion block with nil image/imageData if the image was read from NSURLCache
  32 + * (to be combined with `HHWebImageDownloaderUseNSURLCache`).
  33 + */
  34 + HHWebImageDownloaderIgnoreCachedResponse = 1 << 3,
  35 +
  36 + /**
  37 + * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
  38 + * extra time in background to let the request finish. If the background task expires the operation will be cancelled.
  39 + */
  40 + HHWebImageDownloaderContinueInBackground = 1 << 4,
  41 +
  42 + /**
  43 + * Handles cookies stored in NSHTTPCookieStore by setting
  44 + * NSMutableURLRequest.HTTPShouldHandleCookies = YES;
  45 + */
  46 + HHWebImageDownloaderHandleCookies = 1 << 5,
  47 +
  48 + /**
  49 + * Enable to allow untrusted SSL certificates.
  50 + * Useful for testing purposes. Use with caution in production.
  51 + */
  52 + HHWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6,
  53 +
  54 + /**
  55 + * Put the download in the high queue priority and task priority.
  56 + */
  57 + HHWebImageDownloaderHighPriority = 1 << 7,
  58 +
  59 + /**
  60 + * Scale down the image
  61 + */
  62 + HHWebImageDownloaderScaleDownLargeImages = 1 << 8,
  63 +};
  64 +
  65 +typedef NS_ENUM(NSInteger, HHWebImageDownloaderExecutionOrder) {
  66 + /**
  67 + * Default value. All download operations will execute in queue style (first-in-first-out).
  68 + */
  69 + HHWebImageDownloaderFIFOExecutionOrder,
  70 +
  71 + /**
  72 + * All download operations will execute in stack style (last-in-first-out).
  73 + */
  74 + HHWebImageDownloaderLIFOExecutionOrder
  75 +};
  76 +
  77 +FOUNDATION_EXPORT NSString * _Nonnull const HHWebImageDownloadStartNotification;
  78 +FOUNDATION_EXPORT NSString * _Nonnull const HHWebImageDownloadStopNotification;
  79 +
  80 +typedef void(^HHWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL);
  81 +
  82 +typedef void(^HHWebImageDownloaderCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished);
  83 +
  84 +typedef NSDictionary<NSString *, NSString *> HHHTTPHeadersDictionary;
  85 +typedef NSMutableDictionary<NSString *, NSString *> HHHTTPHeadersMutableDictionary;
  86 +
  87 +typedef HHHTTPHeadersDictionary * _Nullable (^HHWebImageDownloaderHeadersFilterBlock)(NSURL * _Nullable url, HHHTTPHeadersDictionary * _Nullable headers);
  88 +
  89 +/**
  90 + * A token associated with each download. Can be used to cancel a download
  91 + */
  92 +@interface HHWebImageDownloadToken : NSObject <HHWebImageOperation>
  93 +
  94 +/**
  95 + The download's URL. This should be readonly and you should not modify
  96 + */
  97 +@property (nonatomic, strong, nullable) NSURL *url;
  98 +/**
  99 + The cancel token taken from `addHandlersForProgress:completed`. This should be readonly and you should not modify
  100 + @note use `-[HHWebImageDownloadToken cancel]` to cancel the token
  101 + */
  102 +@property (nonatomic, strong, nullable) id downloadOperationCancelToken;
  103 +
  104 +@end
  105 +
  106 +
  107 +/**
  108 + * Asynchronous downloader dedicated and optimized for image loading.
  109 + */
  110 +@interface HHWebImageDownloader : NSObject
  111 +
  112 +/**
  113 + * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory.
  114 + * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
  115 + */
  116 +@property (assign, nonatomic) BOOL shouldDecompressImages;
  117 +
  118 +/**
  119 + * The maximum number of concurrent downloads
  120 + */
  121 +@property (assign, nonatomic) NSInteger maxConcurrentDownloads;
  122 +
  123 +/**
  124 + * Shows the current amount of downloads that still need to be downloaded
  125 + */
  126 +@property (readonly, nonatomic) NSUInteger currentDownloadCount;
  127 +
  128 +/**
  129 + * The timeout value (in seconds) for the download operation. Default: 15.0.
  130 + */
  131 +@property (assign, nonatomic) NSTimeInterval downloadTimeout;
  132 +
  133 +/**
  134 + * The configuration in use by the internal NSURLSession.
  135 + * Mutating this object directly has no effect.
  136 + *
  137 + * @see createNewSessionWithConfiguration:
  138 + */
  139 +@property (readonly, nonatomic, nonnull) NSURLSessionConfiguration *sessionConfiguration;
  140 +
  141 +
  142 +/**
  143 + * Changes download operations execution order. Default value is `HHWebImageDownloaderFIFOExecutionOrder`.
  144 + */
  145 +@property (assign, nonatomic) HHWebImageDownloaderExecutionOrder executionOrder;
  146 +
  147 +/**
  148 + * Singleton method, returns the shared instance
  149 + *
  150 + * @return global shared instance of downloader class
  151 + */
  152 ++ (nonnull instancetype)sharedDownloader;
  153 +
  154 +/**
  155 + * Set the default URL credential to be set for request operations.
  156 + */
  157 +@property (strong, nonatomic, nullable) NSURLCredential *urlCredential;
  158 +
  159 +/**
  160 + * Set username
  161 + */
  162 +@property (strong, nonatomic, nullable) NSString *username;
  163 +
  164 +/**
  165 + * Set password
  166 + */
  167 +@property (strong, nonatomic, nullable) NSString *password;
  168 +
  169 +/**
  170 + * Set filter to pick headers for downloading image HTTP request.
  171 + *
  172 + * This block will be invoked for each downloading image request, returned
  173 + * NHHictionary will be used as headers in corresponding HTTP request.
  174 + */
  175 +@property (nonatomic, copy, nullable) HHWebImageDownloaderHeadersFilterBlock headersFilter;
  176 +
  177 +/**
  178 + * Creates an instance of a downloader with specified session configuration.
  179 + * @note `timeoutIntervalForRequest` is going to be overwritten.
  180 + * @return new instance of downloader class
  181 + */
  182 +- (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)sessionConfiguration NS_DESIGNATED_INITIALIZER;
  183 +
  184 +/**
  185 + * Set a value for a HTTP header to be appended to each download HTTP request.
  186 + *
  187 + * @param value The value for the header field. Use `nil` value to remove the header.
  188 + * @param field The name of the header field to set.
  189 + */
  190 +- (void)setValue:(nullable NSString *)value forHTTPHeaderField:(nullable NSString *)field;
  191 +
  192 +/**
  193 + * Returns the value of the specified HTTP header field.
  194 + *
  195 + * @return The value associated with the header field field, or `nil` if there is no corresponding header field.
  196 + */
  197 +- (nullable NSString *)valueForHTTPHeaderField:(nullable NSString *)field;
  198 +
  199 +/**
  200 + * Sets a subclass of `HHWebImageDownloaderOperation` as the default
  201 + * `NSOperation` to be used each time HHWebImage constructs a request
  202 + * operation to download an image.
  203 + *
  204 + * @param operationClass The subclass of `HHWebImageDownloaderOperation` to set
  205 + * as default. Passing `nil` will revert to `HHWebImageDownloaderOperation`.
  206 + */
  207 +- (void)setOperationClass:(nullable Class)operationClass;
  208 +
  209 +/**
  210 + * Creates a HHWebImageDownloader async downloader instance with a given URL
  211 + *
  212 + * The delegate will be informed when the image is finish downloaded or an error has happen.
  213 + *
  214 + * @see HHWebImageDownloaderDelegate
  215 + *
  216 + * @param url The URL to the image to download
  217 + * @param options The options to be used for this download
  218 + * @param progressBlock A block called repeatedly while the image is downloading
  219 + * @note the progress block is executed on a background queue
  220 + * @param completedBlock A block called once the download is completed.
  221 + * If the download succeeded, the image parameter is set, in case of error,
  222 + * error parameter is set with the error. The last parameter is always YES
  223 + * if HHWebImageDownloaderProgressiveDownload isn't use. With the
  224 + * HHWebImageDownloaderProgressiveDownload option, this block is called
  225 + * repeatedly with the partial image object and the finished argument set to NO
  226 + * before to be called a last time with the full image and finished argument
  227 + * set to YES. In case of error, the finished argument is always YES.
  228 + *
  229 + * @return A token (HHWebImageDownloadToken) that can be passed to -cancel: to cancel this operation
  230 + */
  231 +- (nullable HHWebImageDownloadToken *)downloadImageWithURL:(nullable NSURL *)url
  232 + options:(HHWebImageDownloaderOptions)options
  233 + progress:(nullable HHWebImageDownloaderProgressBlock)progressBlock
  234 + completed:(nullable HHWebImageDownloaderCompletedBlock)completedBlock;
  235 +
  236 +/**
  237 + * Cancels a download that was previously queued using -downloadImageWithURL:options:progress:completed:
  238 + *
  239 + * @param token The token received from -downloadImageWithURL:options:progress:completed: that should be canceled.
  240 + */
  241 +- (void)cancel:(nullable HHWebImageDownloadToken *)token;
  242 +
  243 +/**
  244 + * Sets the download queue suspension state
  245 + */
  246 +- (void)setSuspended:(BOOL)suspended;
  247 +
  248 +/**
  249 + * Cancels all download operations in the queue
  250 + */
  251 +- (void)cancelAllDownloads;
  252 +
  253 +/**
  254 + * Forces HHWebImageDownloader to create and use a new NSURLSession that is
  255 + * initialized with the given configuration.
  256 + * @note All existing download operations in the queue will be cancelled.
  257 + * @note `timeoutIntervalForRequest` is going to be overwritten.
  258 + *
  259 + * @param sessionConfiguration The configuration to use for the new NSURLSession
  260 + */
  261 +- (void)createNewSessionWithConfiguration:(nonnull NSURLSessionConfiguration *)sessionConfiguration;
  262 +
  263 +/**
  264 + * Invalidates the managed session, optionally canceling pending operations.
  265 + * @note If you use custom downloader instead of the shared downloader, you need call this method when you do not use it to avoid memory leak
  266 + * @param cancelPendingOperations Whether or not to cancel pending operations.
  267 + * @note Calling this method on the shared downloader has no effect.
  268 + */
  269 +- (void)invalidateSessionAndCancel:(BOOL)cancelPendingOperations;
  270 +
  271 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageDownloader.h"
  11 +#import "HHWebImageOperation.h"
  12 +
  13 +FOUNDATION_EXPORT NSString * _Nonnull const HHWebImageDownloadStartNotification;
  14 +FOUNDATION_EXPORT NSString * _Nonnull const HHWebImageDownloadReceiveResponseNotification;
  15 +FOUNDATION_EXPORT NSString * _Nonnull const HHWebImageDownloadStopNotification;
  16 +FOUNDATION_EXPORT NSString * _Nonnull const HHWebImageDownloadFinishNotification;
  17 +
  18 +
  19 +
  20 +/**
  21 + Describes a downloader operation. If one wants to use a custom downloader op, it needs to inherit from `NSOperation` and conform to this protocol
  22 + For the description about these methods, see `HHWebImageDownloaderOperation`
  23 + */
  24 +@protocol HHWebImageDownloaderOperationInterface<NSObject>
  25 +
  26 +- (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)request
  27 + inSession:(nullable NSURLSession *)session
  28 + options:(HHWebImageDownloaderOptions)options;
  29 +
  30 +- (nullable id)addHandlersForProgress:(nullable HHWebImageDownloaderProgressBlock)progressBlock
  31 + completed:(nullable HHWebImageDownloaderCompletedBlock)completedBlock;
  32 +
  33 +- (BOOL)shouldDecompressImages;
  34 +- (void)setShouldDecompressImages:(BOOL)value;
  35 +
  36 +- (nullable NSURLCredential *)credential;
  37 +- (void)setCredential:(nullable NSURLCredential *)value;
  38 +
  39 +- (BOOL)cancel:(nullable id)token;
  40 +
  41 +@end
  42 +
  43 +
  44 +@interface HHWebImageDownloaderOperation : NSOperation <HHWebImageDownloaderOperationInterface, HHWebImageOperation, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
  45 +
  46 +/**
  47 + * The request used by the operation's task.
  48 + */
  49 +@property (strong, nonatomic, readonly, nullable) NSURLRequest *request;
  50 +
  51 +/**
  52 + * The operation's task
  53 + */
  54 +@property (strong, nonatomic, readonly, nullable) NSURLSessionTask *dataTask;
  55 +
  56 +
  57 +@property (assign, nonatomic) BOOL shouldDecompressImages;
  58 +
  59 +/**
  60 + * Was used to determine whether the URL connection should consult the credential storage for authenticating the connection.
  61 + * @deprecated Not used for a couple of versions
  62 + */
  63 +@property (nonatomic, assign) BOOL shouldUseCredentialStorage __deprecated_msg("Property deprecated. Does nothing. Kept only for backwards compatibility");
  64 +
  65 +/**
  66 + * The credential used for authentication challenges in `-URLSession:task:didReceiveChallenge:completionHandler:`.
  67 + *
  68 + * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
  69 + */
  70 +@property (nonatomic, strong, nullable) NSURLCredential *credential;
  71 +
  72 +/**
  73 + * The HHWebImageDownloaderOptions for the receiver.
  74 + */
  75 +@property (assign, nonatomic, readonly) HHWebImageDownloaderOptions options;
  76 +
  77 +/**
  78 + * The expected size of data.
  79 + */
  80 +@property (assign, nonatomic) NSInteger expectedSize;
  81 +
  82 +/**
  83 + * The response returned by the operation's task.
  84 + */
  85 +@property (strong, nonatomic, nullable) NSURLResponse *response;
  86 +
  87 +/**
  88 + * Initializes a `HHWebImageDownloaderOperation` object
  89 + *
  90 + * @see HHWebImageDownloaderOperation
  91 + *
  92 + * @param request the URL request
  93 + * @param session the URL session in which this operation will run
  94 + * @param options downloader options
  95 + *
  96 + * @return the initialized instance
  97 + */
  98 +- (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)request
  99 + inSession:(nullable NSURLSession *)session
  100 + options:(HHWebImageDownloaderOptions)options NS_DESIGNATED_INITIALIZER;
  101 +
  102 +/**
  103 + * Adds handlers for progress and completion. Returns a tokent that can be passed to -cancel: to cancel this set of
  104 + * callbacks.
  105 + *
  106 + * @param progressBlock the block executed when a new chunk of data arrives.
  107 + * @note the progress block is executed on a background queue
  108 + * @param completedBlock the block executed when the download is done.
  109 + * @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
  110 + *
  111 + * @return the token to use to cancel this set of handlers
  112 + */
  113 +- (nullable id)addHandlersForProgress:(nullable HHWebImageDownloaderProgressBlock)progressBlock
  114 + completed:(nullable HHWebImageDownloaderCompletedBlock)completedBlock;
  115 +
  116 +/**
  117 + * Cancels a set of callbacks. Once all callbacks are canceled, the operation is cancelled.
  118 + *
  119 + * @param token the token representing a set of callbacks to cancel
  120 + *
  121 + * @return YES if the operation was stopped because this was the last token to be canceled. NO otherwise.
  122 + */
  123 +- (BOOL)cancel:(nullable id)token;
  124 +
  125 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageCompat.h"
  11 +
  12 +@interface HHWebImageFrame : NSObject
  13 +
  14 +// This class is used for creating animated images via `animatedImageWithFrames` in `HHWebImageCoderHelper`. Attention if you need to specify animated images loop count, use `sd_imageLoopCount` property in `UIImage+MultiFormat`.
  15 +
  16 +/**
  17 + The image of current frame. You should not set an animated image.
  18 + */
  19 +@property (nonatomic, strong, readonly, nonnull) UIImage *image;
  20 +/**
  21 + The duration of current frame to be displayed. The number is seconds but not milliseconds. You should not set this to zero.
  22 + */
  23 +@property (nonatomic, readonly, assign) NSTimeInterval duration;
  24 +
  25 +/**
  26 + Create a frame instance with specify image and duration
  27 +
  28 + @param image current frame's image
  29 + @param duration current frame's duration
  30 + @return frame instance
  31 + */
  32 ++ (instancetype _Nonnull)frameWithImage:(UIImage * _Nonnull)image duration:(NSTimeInterval)duration;
  33 +
  34 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageCoder.h"
  11 +
  12 +/**
  13 + Built in coder using ImageIO that supports GIF encoding/decoding
  14 + @note `HHWebImageIOCoder` supports GIF but only as static (will use the 1st frame).
  15 + @note Use `HHWebImageGIFCoder` for fully animated GIFs - less performant than `FLAnimatedImage`
  16 + @note If you decide to make all `UIImageView`(including `FLAnimatedImageView`) instance support GIF. You should add this coder to `HHWebImageCodersManager` and make sure that it has a higher priority than `HHWebImageIOCoder`
  17 + @note The recommended approach for animated GIFs is using `FLAnimatedImage`. It's more performant than `UIImageView` for GIF displaying
  18 + */
  19 +@interface HHWebImageGIFCoder : NSObject <HHWebImageCoder>
  20 +
  21 ++ (nonnull instancetype)sharedCoder;
  22 +
  23 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageCoder.h"
  11 +
  12 +/**
  13 + Built in coder that supports PNG, JPEG, TIFF, includes support for progressive decoding.
  14 +
  15 + GIF
  16 + Also supports static GIF (meaning will only handle the 1st frame).
  17 + For a full GIF support, we recommend `FLAnimatedImage` or our less performant `HHWebImageGIFCoder`
  18 +
  19 + HEIC
  20 + This coder also supports HEIC format because ImageIO supports it natively. But it depends on the system capabilities, so it won't work on all devices, see: https://devstreaming-cdn.apple.com/videos/wwdc/2017/511tj33587vdhds/511/511_working_with_heif_and_hevc.pdf
  21 + Decode(Software): !Simulator && (iOS 11 || tvOS 11 || macOS 10.13)
  22 + Decode(Hardware): !Simulator && ((iOS 11 && A9Chip) || (macOS 10.13 && 6thGenerationIntelCPU))
  23 + Encode(Software): macOS 10.13
  24 + Encode(Hardware): !Simulator && ((iOS 11 && A10FusionChip) || (macOS 10.13 && 6thGenerationIntelCPU))
  25 + */
  26 +@interface HHWebImageImageIOCoder : NSObject <HHWebImageProgressiveCoder>
  27 +
  28 ++ (nonnull instancetype)sharedCoder;
  29 +
  30 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +#import "HHWebImageOperation.h"
  11 +#import "HHWebImageDownloader.h"
  12 +#import "HHImageCache.h"
  13 +
  14 +typedef NS_OPTIONS(NSUInteger, HHWebImageOptions) {
  15 + /**
  16 + * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying.
  17 + * This flag disable this blacklisting.
  18 + */
  19 + HHWebImageRetryFailed = 1 << 0,
  20 +
  21 + /**
  22 + * By default, image downloads are started during UI interactions, this flags disable this feature,
  23 + * leading to delayed download on UIScrollView deceleration for instance.
  24 + */
  25 + HHWebImageLowPriority = 1 << 1,
  26 +
  27 + /**
  28 + * This flag disables on-disk caching after the download finished, only cache in memory
  29 + */
  30 + HHWebImageCacheMemoryOnly = 1 << 2,
  31 +
  32 + /**
  33 + * This flag enables progressive download, the image is displayed progressively during download as a browser would do.
  34 + * By default, the image is only displayed once completely downloaded.
  35 + */
  36 + HHWebImageProgressiveDownload = 1 << 3,
  37 +
  38 + /**
  39 + * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed.
  40 + * The disk caching will be handled by NSURLCache instead of HHWebImage leading to slight performance degradation.
  41 + * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.
  42 + * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.
  43 + *
  44 + * Use this flag only if you can't make your URLs static with embedded cache busting parameter.
  45 + */
  46 + HHWebImageRefreshCached = 1 << 4,
  47 +
  48 + /**
  49 + * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
  50 + * extra time in background to let the request finish. If the background task expires the operation will be cancelled.
  51 + */
  52 + HHWebImageContinueInBackground = 1 << 5,
  53 +
  54 + /**
  55 + * Handles cookies stored in NSHTTPCookieStore by setting
  56 + * NSMutableURLRequest.HTTPShouldHandleCookies = YES;
  57 + */
  58 + HHWebImageHandleCookies = 1 << 6,
  59 +
  60 + /**
  61 + * Enable to allow untrusted SSL certificates.
  62 + * Useful for testing purposes. Use with caution in production.
  63 + */
  64 + HHWebImageAllowInvalidSSLCertificates = 1 << 7,
  65 +
  66 + /**
  67 + * By default, images are loaded in the order in which they were queued. This flag moves them to
  68 + * the front of the queue.
  69 + */
  70 + HHWebImageHighPriority = 1 << 8,
  71 +
  72 + /**
  73 + * By default, placeholder images are loaded while the image is loading. This flag will delay the loading
  74 + * of the placeholder image until after the image has finished loading.
  75 + */
  76 + HHWebImageDelayPlaceholder = 1 << 9,
  77 +
  78 + /**
  79 + * We usually don't call transformDownloadedImage delegate method on animated images,
  80 + * as most transformation code would mangle it.
  81 + * Use this flag to transform them anyway.
  82 + */
  83 + HHWebImageTransformAnimatedImage = 1 << 10,
  84 +
  85 + /**
  86 + * By default, image is added to the imageView after download. But in some cases, we want to
  87 + * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance)
  88 + * Use this flag if you want to manually set the image in the completion when success
  89 + */
  90 + HHWebImageAvoidAutoSetImage = 1 << 11,
  91 +
  92 + /**
  93 + * By default, images are decoded respecting their original size. On iOS, this flag will scale down the
  94 + * images to a size compatible with the constrained memory of devices.
  95 + * If `HHWebImageProgressiveDownload` flag is set the scale down is deactivated.
  96 + */
  97 + HHWebImageScaleDownLargeImages = 1 << 12,
  98 +
  99 + /**
  100 + * By default, we do not query disk data when the image is cached in memory. This mask can force to query disk data at the same time.
  101 + * This flag is recommend to be used with `HHWebImageQueryDiskSync` to ensure the image is loaded in the same runloop.
  102 + */
  103 + HHWebImageQueryDataWhenInMemory = 1 << 13,
  104 +
  105 + /**
  106 + * By default, we query the memory cache synchronously, disk cache asynchronously. This mask can force to query disk cache synchronously to ensure that image is loaded in the same runloop.
  107 + * This flag can avoid flashing during cell reuse if you disable memory cache or in some other cases.
  108 + */
  109 + HHWebImageQueryDiskSync = 1 << 14,
  110 +
  111 + /**
  112 + * By default, when the cache missed, the image is download from the network. This flag can prevent network to load from cache only.
  113 + */
  114 + HHWebImageFromCacheOnly = 1 << 15,
  115 + /**
  116 + * By default, when you use `HHWebImageTransition` to do some view transition after the image load finished, this transition is only applied for image download from the network. This mask can force to apply view transition for memory and disk cache as well.
  117 + */
  118 + HHWebImageForceTransition = 1 << 16
  119 +};
  120 +
  121 +typedef void(^HHExternalCompletionBlock)(UIImage * _Nullable image, NSError * _Nullable error, HHImageCacheType cacheType, NSURL * _Nullable imageURL);
  122 +
  123 +typedef void(^HHInternalCompletionBlock)(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, HHImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL);
  124 +
  125 +typedef NSString * _Nullable(^HHWebImageCacheKeyFilterBlock)(NSURL * _Nullable url);
  126 +
  127 +typedef NSData * _Nullable(^HHWebImageCacheSerializerBlock)(UIImage * _Nonnull image, NSData * _Nullable data, NSURL * _Nullable imageURL);
  128 +
  129 +
  130 +@class HHWebImageManager;
  131 +
  132 +@protocol HHWebImageManagerDelegate <NSObject>
  133 +
  134 +@optional
  135 +
  136 +/**
  137 + * Controls which image should be downloaded when the image is not found in the cache.
  138 + *
  139 + * @param imageManager The current `HHWebImageManager`
  140 + * @param imageURL The url of the image to be downloaded
  141 + *
  142 + * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied.
  143 + */
  144 +- (BOOL)imageManager:(nonnull HHWebImageManager *)imageManager shouldDownloadImageForURL:(nullable NSURL *)imageURL;
  145 +
  146 +/**
  147 + * Controls the complicated logic to mark as failed URLs when download error occur.
  148 + * If the delegate implement this method, we will not use the built-in way to mark URL as failed based on error code;
  149 + @param imageManager The current `HHWebImageManager`
  150 + @param imageURL The url of the image
  151 + @param error The download error for the url
  152 + @return Whether to block this url or not. Return YES to mark this URL as failed.
  153 + */
  154 +- (BOOL)imageManager:(nonnull HHWebImageManager *)imageManager shouldBlockFailedURL:(nonnull NSURL *)imageURL withError:(nonnull NSError *)error;
  155 +
  156 +/**
  157 + * Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory.
  158 + * NOTE: This method is called from a global queue in order to not to block the main thread.
  159 + *
  160 + * @param imageManager The current `HHWebImageManager`
  161 + * @param image The image to transform
  162 + * @param imageURL The url of the image to transform
  163 + *
  164 + * @return The transformed image object.
  165 + */
  166 +- (nullable UIImage *)imageManager:(nonnull HHWebImageManager *)imageManager transformDownloadedImage:(nullable UIImage *)image withURL:(nullable NSURL *)imageURL;
  167 +
  168 +@end
  169 +
  170 +/**
  171 + * The HHWebImageManager is the class behind the UIImageView+WebCache category and likes.
  172 + * It ties the asynchronous downloader (HHWebImageDownloader) with the image cache store (HHImageCache).
  173 + * You can use this class directly to benefit from web image downloading with caching in another context than
  174 + * a UIView.
  175 + *
  176 + * Here is a simple example of how to use HHWebImageManager:
  177 + *
  178 + * @code
  179 +
  180 +HHWebImageManager *manager = [HHWebImageManager sharedManager];
  181 +[manager loadImageWithURL:imageURL
  182 + options:0
  183 + progress:nil
  184 + completed:^(UIImage *image, NSError *error, HHImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  185 + if (image) {
  186 + // do something with image
  187 + }
  188 + }];
  189 +
  190 + * @endcode
  191 + */
  192 +@interface HHWebImageManager : NSObject
  193 +
  194 +@property (weak, nonatomic, nullable) id <HHWebImageManagerDelegate> delegate;
  195 +
  196 +@property (strong, nonatomic, readonly, nullable) HHImageCache *imageCache;
  197 +@property (strong, nonatomic, readonly, nullable) HHWebImageDownloader *imageDownloader;
  198 +
  199 +/**
  200 + * The cache filter is a block used each time HHWebImageManager need to convert an URL into a cache key. This can
  201 + * be used to remove dynamic part of an image URL.
  202 + *
  203 + * The following example sets a filter in the application delegate that will remove any query-string from the
  204 + * URL before to use it as a cache key:
  205 + *
  206 + * @code
  207 +
  208 +HHWebImageManager.sharedManager.cacheKeyFilter = ^(NSURL * _Nullable url) {
  209 + url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
  210 + return [url absoluteString];
  211 +};
  212 +
  213 + * @endcode
  214 + */
  215 +@property (nonatomic, copy, nullable) HHWebImageCacheKeyFilterBlock cacheKeyFilter;
  216 +
  217 +/**
  218 + * The cache serializer is a block used to convert the decoded image, the source downloaded data, to the actual data used for storing to the disk cache. If you return nil, means to generate the data from the image instance, see `HHImageCache`.
  219 + * For example, if you are using WebP images and facing the slow decoding time issue when later retriving from disk cache again. You can try to encode the decoded image to JPEG/PNG format to disk cache instead of source downloaded data.
  220 + * @note The `image` arg is nonnull, but when you also provide a image transformer and the image is transformed, the `data` arg may be nil, take attention to this case.
  221 + * @note This method is called from a global queue in order to not to block the main thread.
  222 + * @code
  223 + HHWebImageManager.sharedManager.cacheKeyFilter = ^NHHata * _Nullable(UIImage * _Nonnull image, NSData * _Nullable data, NSURL * _Nullable imageURL) {
  224 + HHImageFormat format = [NSData sd_imageFormatForImageData:data];
  225 + switch (format) {
  226 + case HHImageFormatWebP:
  227 + return image.images ? data : nil;
  228 + default:
  229 + return data;
  230 + }
  231 + };
  232 + * @endcode
  233 + * The default value is nil. Means we just store the source downloaded data to disk cache.
  234 + */
  235 +@property (nonatomic, copy, nullable) HHWebImageCacheSerializerBlock cacheSerializer;
  236 +
  237 +/**
  238 + * Returns global HHWebImageManager instance.
  239 + *
  240 + * @return HHWebImageManager shared instance
  241 + */
  242 ++ (nonnull instancetype)sharedManager;
  243 +
  244 +/**
  245 + * Allows to specify instance of cache and image downloader used with image manager.
  246 + * @return new instance of `HHWebImageManager` with specified cache and downloader.
  247 + */
  248 +- (nonnull instancetype)initWithCache:(nonnull HHImageCache *)cache downloader:(nonnull HHWebImageDownloader *)downloader NS_DESIGNATED_INITIALIZER;
  249 +
  250 +/**
  251 + * Downloads the image at the given URL if not present in cache or return the cached version otherwise.
  252 + *
  253 + * @param url The URL to the image
  254 + * @param options A mask to specify options to use for this request
  255 + * @param progressBlock A block called while image is downloading
  256 + * @note the progress block is executed on a background queue
  257 + * @param completedBlock A block called when operation has been completed.
  258 + *
  259 + * This parameter is required.
  260 + *
  261 + * This block has no return value and takes the requested UIImage as first parameter and the NHHata representation as second parameter.
  262 + * In case of error the image parameter is nil and the third parameter may contain an NSError.
  263 + *
  264 + * The forth parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache
  265 + * or from the memory cache or from the network.
  266 + *
  267 + * The fith parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is
  268 + * downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the
  269 + * block is called a last time with the full image and the last parameter set to YES.
  270 + *
  271 + * The last parameter is the original image URL
  272 + *
  273 + * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
  274 + */
  275 +- (nullable id <HHWebImageOperation>)loadImageWithURL:(nullable NSURL *)url
  276 + options:(HHWebImageOptions)options
  277 + progress:(nullable HHWebImageDownloaderProgressBlock)progressBlock
  278 + completed:(nullable HHInternalCompletionBlock)completedBlock;
  279 +
  280 +/**
  281 + * Saves image to cache for given URL
  282 + *
  283 + * @param image The image to cache
  284 + * @param url The URL to the image
  285 + *
  286 + */
  287 +
  288 +- (void)saveImageToCache:(nullable UIImage *)image forURL:(nullable NSURL *)url;
  289 +
  290 +/**
  291 + * Cancel all current operations
  292 + */
  293 +- (void)cancelAll;
  294 +
  295 +/**
  296 + * Check one or more operations running
  297 + */
  298 +- (BOOL)isRunning;
  299 +
  300 +/**
  301 + * Async check if image has already been cached
  302 + *
  303 + * @param url image url
  304 + * @param completionBlock the block to be executed when the check is finished
  305 + *
  306 + * @note the completion block is always executed on the main queue
  307 + */
  308 +- (void)cachedImageExistsForURL:(nullable NSURL *)url
  309 + completion:(nullable HHWebImageCheckCacheCompletionBlock)completionBlock;
  310 +
  311 +/**
  312 + * Async check if image has already been cached on disk only
  313 + *
  314 + * @param url image url
  315 + * @param completionBlock the block to be executed when the check is finished
  316 + *
  317 + * @note the completion block is always executed on the main queue
  318 + */
  319 +- (void)diskImageExistsForURL:(nullable NSURL *)url
  320 + completion:(nullable HHWebImageCheckCacheCompletionBlock)completionBlock;
  321 +
  322 +
  323 +/**
  324 + *Return the cache key for a given URL
  325 + */
  326 +- (nullable NSString *)cacheKeyForURL:(nullable NSURL *)url;
  327 +
  328 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +@protocol HHWebImageOperation <NSObject>
  12 +
  13 +- (void)cancel;
  14 +
  15 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "HHWebImageManager.h"
  11 +
  12 +@class HHWebImagePrefetcher;
  13 +
  14 +@protocol HHWebImagePrefetcherDelegate <NSObject>
  15 +
  16 +@optional
  17 +
  18 +/**
  19 + * Called when an image was prefetched.
  20 + *
  21 + * @param imagePrefetcher The current image prefetcher
  22 + * @param imageURL The image url that was prefetched
  23 + * @param finishedCount The total number of images that were prefetched (successful or not)
  24 + * @param totalCount The total number of images that were to be prefetched
  25 + */
  26 +- (void)imagePrefetcher:(nonnull HHWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(nullable NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
  27 +
  28 +/**
  29 + * Called when all images are prefetched.
  30 + * @param imagePrefetcher The current image prefetcher
  31 + * @param totalCount The total number of images that were prefetched (whether successful or not)
  32 + * @param skippedCount The total number of images that were skipped
  33 + */
  34 +- (void)imagePrefetcher:(nonnull HHWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
  35 +
  36 +@end
  37 +
  38 +typedef void(^HHWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls);
  39 +typedef void(^HHWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls);
  40 +
  41 +/**
  42 + * Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
  43 + */
  44 +@interface HHWebImagePrefetcher : NSObject
  45 +
  46 +/**
  47 + * The web image manager
  48 + */
  49 +@property (strong, nonatomic, readonly, nonnull) HHWebImageManager *manager;
  50 +
  51 +/**
  52 + * Maximum number of URLs to prefetch at the same time. Defaults to 3.
  53 + */
  54 +@property (nonatomic, assign) NSUInteger maxConcurrentDownloads;
  55 +
  56 +/**
  57 + * HHWebImageOptions for prefetcher. Defaults to HHWebImageLowPriority.
  58 + */
  59 +@property (nonatomic, assign) HHWebImageOptions options;
  60 +
  61 +/**
  62 + * Queue options for Prefetcher. Defaults to Main Queue.
  63 + */
  64 +@property (strong, nonatomic, nonnull) dispatch_queue_t prefetcherQueue;
  65 +
  66 +@property (weak, nonatomic, nullable) id <HHWebImagePrefetcherDelegate> delegate;
  67 +
  68 +/**
  69 + * Return the global image prefetcher instance.
  70 + */
  71 ++ (nonnull instancetype)sharedImagePrefetcher;
  72 +
  73 +/**
  74 + * Allows you to instantiate a prefetcher with any arbitrary image manager.
  75 + */
  76 +- (nonnull instancetype)initWithImageManager:(nonnull HHWebImageManager *)manager NS_DESIGNATED_INITIALIZER;
  77 +
  78 +/**
  79 + * Assign list of URLs to let HHWebImagePrefetcher to queue the prefetching,
  80 + * currently one image is downloaded at a time,
  81 + * and skips images for failed downloads and proceed to the next image in the list.
  82 + * Any previously-running prefetch operations are canceled.
  83 + *
  84 + * @param urls list of URLs to prefetch
  85 + */
  86 +- (void)prefetchURLs:(nullable NSArray<NSURL *> *)urls;
  87 +
  88 +/**
  89 + * Assign list of URLs to let HHWebImagePrefetcher to queue the prefetching,
  90 + * currently one image is downloaded at a time,
  91 + * and skips images for failed downloads and proceed to the next image in the list.
  92 + * Any previously-running prefetch operations are canceled.
  93 + *
  94 + * @param urls list of URLs to prefetch
  95 + * @param progressBlock block to be called when progress updates;
  96 + * first parameter is the number of completed (successful or not) requests,
  97 + * second parameter is the total number of images originally requested to be prefetched
  98 + * @param completionBlock block to be called when prefetching is completed
  99 + * first param is the number of completed (successful or not) requests,
  100 + * second parameter is the number of skipped requests
  101 + */
  102 +- (void)prefetchURLs:(nullable NSArray<NSURL *> *)urls
  103 + progress:(nullable HHWebImagePrefetcherProgressBlock)progressBlock
  104 + completed:(nullable HHWebImagePrefetcherCompletionBlock)completionBlock;
  105 +
  106 +/**
  107 + * Remove and cancel queued list
  108 + */
  109 +- (void)cancelPrefetching;
  110 +
  111 +
  112 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +
  11 +#if HH_UIKIT || HH_MAC
  12 +#import "HHImageCache.h"
  13 +
  14 +// This class is used to provide a transition animation after the view category load image finished. Use this on `sd_imageTransition` in UIView+WebCache.h
  15 +// for UIKit(iOS & tvOS), we use `+[UIView transitionWithView:duration:options:animations:completion]` for transition animation.
  16 +// for AppKit(macOS), we use `+[NSAnimationContext runAnimationGroup:completionHandler:]` for transition animation. You can call `+[NSAnimationContext currentContext]` to grab the context during animations block.
  17 +// These transition are provided for basic usage. If you need complicated animation, consider to directly use Core Animation or use `HHWebImageAvoidAutoSetImage` and implement your own after image load finished.
  18 +
  19 +#if HH_UIKIT
  20 +typedef UIViewAnimationOptions HHWebImageAnimationOptions;
  21 +#else
  22 +typedef NS_OPTIONS(NSUInteger, HHWebImageAnimationOptions) {
  23 + HHWebImageAnimationOptionAllowsImplicitAnimation = 1 << 0, // specify `allowsImplicitAnimation` for the `NSAnimationContext`
  24 +};
  25 +#endif
  26 +
  27 +typedef void (^HHWebImageTransitionPreparesBlock)(__kindof UIView * _Nonnull view, UIImage * _Nullable image, NSData * _Nullable imageData, HHImageCacheType cacheType, NSURL * _Nullable imageURL);
  28 +typedef void (^HHWebImageTransitionAnimationsBlock)(__kindof UIView * _Nonnull view, UIImage * _Nullable image);
  29 +typedef void (^HHWebImageTransitionCompletionBlock)(BOOL finished);
  30 +
  31 +@interface HHWebImageTransition : NSObject
  32 +
  33 +/**
  34 + By default, we set the image to the view at the beginning of the animtions. You can disable this and provide custom set image process
  35 + */
  36 +@property (nonatomic, assign) BOOL avoidAutoSetImage;
  37 +/**
  38 + The duration of the transition animation, measured in seconds. Defaults to 0.5.
  39 + */
  40 +@property (nonatomic, assign) NSTimeInterval duration;
  41 +/**
  42 + The timing function used for all animations within this transition animation (macOS).
  43 + */
  44 +@property (nonatomic, strong, nullable) CAMediaTimingFunction *timingFunction NS_AVAILABLE_MAC(10_7);
  45 +/**
  46 + A mask of options indicating how you want to perform the animations.
  47 + */
  48 +@property (nonatomic, assign) HHWebImageAnimationOptions animationOptions;
  49 +/**
  50 + A block object to be executed before the animation sequence starts.
  51 + */
  52 +@property (nonatomic, copy, nullable) HHWebImageTransitionPreparesBlock prepares;
  53 +/**
  54 + A block object that contains the changes you want to make to the specified view.
  55 + */
  56 +@property (nonatomic, copy, nullable) HHWebImageTransitionAnimationsBlock animations;
  57 +/**
  58 + A block object to be executed when the animation sequence ends.
  59 + */
  60 +@property (nonatomic, copy, nullable) HHWebImageTransitionCompletionBlock completion;
  61 +
  62 +@end
  63 +
  64 +// Convenience way to create transition. Remember to specify the duration if needed.
  65 +// for UIKit, these transition just use the correspond `animationOptions`
  66 +// for AppKit, these transition use Core Animation in `animations`. So your view must be layer-backed. Set `wantsLayer = YES` before you apply it.
  67 +
  68 +@interface HHWebImageTransition (Conveniences)
  69 +
  70 +// class property is available in Xcode 8. We will drop the Xcode 7.3 support in 5.x
  71 +#if __has_feature(objc_class_property)
  72 +/// Fade transition.
  73 +@property (nonatomic, class, nonnull, readonly) HHWebImageTransition *fadeTransition;
  74 +/// Flip from left transition.
  75 +@property (nonatomic, class, nonnull, readonly) HHWebImageTransition *flipFromLeftTransition;
  76 +/// Flip from right transition.
  77 +@property (nonatomic, class, nonnull, readonly) HHWebImageTransition *flipFromRightTransition;
  78 +/// Flip from top transition.
  79 +@property (nonatomic, class, nonnull, readonly) HHWebImageTransition *flipFromTopTransition;
  80 +/// Flip from bottom transition.
  81 +@property (nonatomic, class, nonnull, readonly) HHWebImageTransition *flipFromBottomTransition;
  82 +/// Curl up transition.
  83 +@property (nonatomic, class, nonnull, readonly) HHWebImageTransition *curlUpTransition;
  84 +/// Curl down transition.
  85 +@property (nonatomic, class, nonnull, readonly) HHWebImageTransition *curlDownTransition;
  86 +#else
  87 ++ (nonnull instancetype)fadeTransition;
  88 ++ (nonnull instancetype)flipFromLeftTransition;
  89 ++ (nonnull instancetype)flipFromRightTransition;
  90 ++ (nonnull instancetype)flipFromTopTransition;
  91 ++ (nonnull instancetype)flipFromBottomTransition;
  92 ++ (nonnull instancetype)curlUpTransition;
  93 ++ (nonnull instancetype)curlDownTransition;
  94 +#endif
  95 +
  96 +@end
  97 +
  98 +#endif
  1 +//
  2 +// HttpsDNSAuth.h
  3 +// HHDoctorSDK
  4 +//
  5 +// Created by Shi Jian on 2018/8/9.
  6 +//
  7 +
  8 +#import <UIKit/UIKit.h>
  9 +
  10 +@interface HttpsDNSAuth : NSObject
  11 +
  12 +
  13 +//+ (void)sendRequest:(NSURLAuthenticationChallenge *)challenge request:(NSMutableURLRequest *)request;
  14 +
  15 ++ (void)requestHost:(NSString *_Nullable)host didReceiveChallenge:(NSURLAuthenticationChallenge *_Nullable)challenge completionHandler:(void (^_Nonnull)(NSURLSessionAuthChallengeDisposition, NSURLCredential *_Nullable))completionHandler;
  16 +
  17 +@end
  1 +/*
  2 + * This file is part of the HHWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + * (c) Fabrice Aneche
  5 + *
  6 + * For the full copyright and license information, please view the LICENSE
  7 + * file that was distributed with this source code.
  8 + */
  9 +
  10 +#import <Foundation/Foundation.h>
  11 +#import "HHWebImageCompat.h"
  12 +
  13 +typedef NS_ENUM(NSInteger, HHImageFormat) {
  14 + HHImageFormatUndefined = -1,
  15 + HHImageFormatJPEG = 0,
  16 + HHImageFormatPNG,
  17 + HHImageFormatGIF,
  18 + HHImageFormatTIFF,
  19 + HHImageFormatWebP,
  20 + HHImageFormatHEIC
  21 +};
  22 +
  23 +@interface NSData (hhImageContentType)
  24 +
  25 +/**
  26 + * Return image format
  27 + *
  28 + * @param data the input image data
  29 + *
  30 + * @return the image format as `HHImageFormat` (enum)
  31 + */
  32 ++ (HHImageFormat)HH_imageFormatForImageData:(nullable NSData *)data;
  33 +
  34 +/**
  35 + Convert HHImageFormat to UTType
  36 +
  37 + @param format Format as HHImageFormat
  38 + @return The UTType as CFStringRef
  39 + */
  40 ++ (nonnull CFStringRef)HH_UTTypeFromHHImageFormat:(HHImageFormat)format;
  41 +
  42 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +
  11 +#if HH_MAC
  12 +
  13 +#import <Cocoa/Cocoa.h>
  14 +
  15 +@interface NSImage (hhWebCache)
  16 +
  17 +- (CGImageRef)CGImage;
  18 +- (NSArray<NSImage *> *)images;
  19 +- (BOOL)isGIF;
  20 +
  21 +@end
  22 +
  23 +#endif
  1 +//
  2 +// ObjectMapper.h
  3 +// ObjectMapper
  4 +//
  5 +// Created by Tristan Himmelman on 2014-10-16.
  6 +//
  7 +// The MIT License (MIT)
  8 +//
  9 +// Copyright (c) 2014-2018 Tristan Himmelman
  10 +//
  11 +// Permission is hereby granted, free of charge, to any person obtaining a copy
  12 +// of this software and associated documentation files (the "Software"), to deal
  13 +// in the Software without restriction, including without limitation the rights
  14 +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15 +// copies of the Software, and to permit persons to whom the Software is
  16 +// furnished to do so, subject to the following conditions:
  17 +//
  18 +// The above copyright notice and this permission notice shall be included in
  19 +// all copies or substantial portions of the Software.
  20 +//
  21 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22 +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23 +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24 +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25 +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26 +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27 +// THE SOFTWARE.
  28 +
  29 +
  30 +#import <Foundation/Foundation.h>
  31 +
  32 +//! Project version number for ObjectMapper.
  33 +FOUNDATION_EXPORT double ObjectMapperVersionNumber;
  34 +
  35 +//! Project version string for ObjectMapper.
  36 +FOUNDATION_EXPORT const unsigned char ObjectMapperVersionString[];
  37 +
  38 +// In this header, you should import all the public headers of your framework using statements like #import <ObjectMapper/PublicHeader.h>
  39 +
  40 +
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +
  11 +#if HH_UIKIT
  12 +
  13 +#import "HHWebImageManager.h"
  14 +
  15 +/**
  16 + * Integrates HHWebImage async downloading and caching of remote images with UIButtonView.
  17 + */
  18 +@interface UIButton (hhWebCache)
  19 +
  20 +#pragma mark - Image
  21 +
  22 +/**
  23 + * Get the current image URL.
  24 + */
  25 +- (nullable NSURL *)HH_currentImageURL;
  26 +
  27 +/**
  28 + * Get the image URL for a control state.
  29 + *
  30 + * @param state Which state you want to know the URL for. The values are described in UIControlState.
  31 + */
  32 +- (nullable NSURL *)HH_imageURLForState:(UIControlState)state;
  33 +
  34 +/**
  35 + * Set the imageView `image` with an `url`.
  36 + *
  37 + * The download is asynchronous and cached.
  38 + *
  39 + * @param url The url for the image.
  40 + * @param state The state that uses the specified title. The values are described in UIControlState.
  41 + */
  42 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  43 + forState:(UIControlState)state NS_REFINED_FOR_SWIFT;
  44 +
  45 +/**
  46 + * Set the imageView `image` with an `url` and a placeholder.
  47 + *
  48 + * The download is asynchronous and cached.
  49 + *
  50 + * @param url The url for the image.
  51 + * @param state The state that uses the specified title. The values are described in UIControlState.
  52 + * @param placeholder The image to be set initially, until the image request finishes.
  53 + * @see HH_setImageWithURL:placeholderImage:options:
  54 + */
  55 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  56 + forState:(UIControlState)state
  57 + placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
  58 +
  59 +/**
  60 + * Set the imageView `image` with an `url`, placeholder and custom options.
  61 + *
  62 + * The download is asynchronous and cached.
  63 + *
  64 + * @param url The url for the image.
  65 + * @param state The state that uses the specified title. The values are described in UIControlState.
  66 + * @param placeholder The image to be set initially, until the image request finishes.
  67 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  68 + */
  69 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  70 + forState:(UIControlState)state
  71 + placeholderImage:(nullable UIImage *)placeholder
  72 + options:(HHWebImageOptions)options NS_REFINED_FOR_SWIFT;
  73 +
  74 +/**
  75 + * Set the imageView `image` with an `url`.
  76 + *
  77 + * The download is asynchronous and cached.
  78 + *
  79 + * @param url The url for the image.
  80 + * @param state The state that uses the specified title. The values are described in UIControlState.
  81 + * @param completedBlock A block called when operation has been completed. This block has no return value
  82 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  83 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  84 + * indicating if the image was retrieved from the local cache or from the network.
  85 + * The fourth parameter is the original image url.
  86 + */
  87 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  88 + forState:(UIControlState)state
  89 + completed:(nullable HHExternalCompletionBlock)completedBlock;
  90 +
  91 +/**
  92 + * Set the imageView `image` with an `url`, placeholder.
  93 + *
  94 + * The download is asynchronous and cached.
  95 + *
  96 + * @param url The url for the image.
  97 + * @param state The state that uses the specified title. The values are described in UIControlState.
  98 + * @param placeholder The image to be set initially, until the image request finishes.
  99 + * @param completedBlock A block called when operation has been completed. This block has no return value
  100 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  101 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  102 + * indicating if the image was retrieved from the local cache or from the network.
  103 + * The fourth parameter is the original image url.
  104 + */
  105 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  106 + forState:(UIControlState)state
  107 + placeholderImage:(nullable UIImage *)placeholder
  108 + completed:(nullable HHExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
  109 +
  110 +/**
  111 + * Set the imageView `image` with an `url`, placeholder and custom options.
  112 + *
  113 + * The download is asynchronous and cached.
  114 + *
  115 + * @param url The url for the image.
  116 + * @param state The state that uses the specified title. The values are described in UIControlState.
  117 + * @param placeholder The image to be set initially, until the image request finishes.
  118 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  119 + * @param completedBlock A block called when operation has been completed. This block has no return value
  120 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  121 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  122 + * indicating if the image was retrieved from the local cache or from the network.
  123 + * The fourth parameter is the original image url.
  124 + */
  125 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  126 + forState:(UIControlState)state
  127 + placeholderImage:(nullable UIImage *)placeholder
  128 + options:(HHWebImageOptions)options
  129 + completed:(nullable HHExternalCompletionBlock)completedBlock;
  130 +
  131 +#pragma mark - Background Image
  132 +
  133 +/**
  134 + * Get the current background image URL.
  135 + */
  136 +- (nullable NSURL *)HH_currentBackgroundImageURL;
  137 +
  138 +/**
  139 + * Get the background image URL for a control state.
  140 + *
  141 + * @param state Which state you want to know the URL for. The values are described in UIControlState.
  142 + */
  143 +- (nullable NSURL *)HH_backgroundImageURLForState:(UIControlState)state;
  144 +
  145 +/**
  146 + * Set the backgroundImageView `image` with an `url`.
  147 + *
  148 + * The download is asynchronous and cached.
  149 + *
  150 + * @param url The url for the image.
  151 + * @param state The state that uses the specified title. The values are described in UIControlState.
  152 + */
  153 +- (void)HH_setBackgroundImageWithURL:(nullable NSURL *)url
  154 + forState:(UIControlState)state NS_REFINED_FOR_SWIFT;
  155 +
  156 +/**
  157 + * Set the backgroundImageView `image` with an `url` and a placeholder.
  158 + *
  159 + * The download is asynchronous and cached.
  160 + *
  161 + * @param url The url for the image.
  162 + * @param state The state that uses the specified title. The values are described in UIControlState.
  163 + * @param placeholder The image to be set initially, until the image request finishes.
  164 + * @see HH_setImageWithURL:placeholderImage:options:
  165 + */
  166 +- (void)HH_setBackgroundImageWithURL:(nullable NSURL *)url
  167 + forState:(UIControlState)state
  168 + placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
  169 +
  170 +/**
  171 + * Set the backgroundImageView `image` with an `url`, placeholder and custom options.
  172 + *
  173 + * The download is asynchronous and cached.
  174 + *
  175 + * @param url The url for the image.
  176 + * @param state The state that uses the specified title. The values are described in UIControlState.
  177 + * @param placeholder The image to be set initially, until the image request finishes.
  178 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  179 + */
  180 +- (void)HH_setBackgroundImageWithURL:(nullable NSURL *)url
  181 + forState:(UIControlState)state
  182 + placeholderImage:(nullable UIImage *)placeholder
  183 + options:(HHWebImageOptions)options NS_REFINED_FOR_SWIFT;
  184 +
  185 +/**
  186 + * Set the backgroundImageView `image` with an `url`.
  187 + *
  188 + * The download is asynchronous and cached.
  189 + *
  190 + * @param url The url for the image.
  191 + * @param state The state that uses the specified title. The values are described in UIControlState.
  192 + * @param completedBlock A block called when operation has been completed. This block has no return value
  193 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  194 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  195 + * indicating if the image was retrieved from the local cache or from the network.
  196 + * The fourth parameter is the original image url.
  197 + */
  198 +- (void)HH_setBackgroundImageWithURL:(nullable NSURL *)url
  199 + forState:(UIControlState)state
  200 + completed:(nullable HHExternalCompletionBlock)completedBlock;
  201 +
  202 +/**
  203 + * Set the backgroundImageView `image` with an `url`, placeholder.
  204 + *
  205 + * The download is asynchronous and cached.
  206 + *
  207 + * @param url The url for the image.
  208 + * @param state The state that uses the specified title. The values are described in UIControlState.
  209 + * @param placeholder The image to be set initially, until the image request finishes.
  210 + * @param completedBlock A block called when operation has been completed. This block has no return value
  211 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  212 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  213 + * indicating if the image was retrieved from the local cache or from the network.
  214 + * The fourth parameter is the original image url.
  215 + */
  216 +- (void)HH_setBackgroundImageWithURL:(nullable NSURL *)url
  217 + forState:(UIControlState)state
  218 + placeholderImage:(nullable UIImage *)placeholder
  219 + completed:(nullable HHExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
  220 +
  221 +/**
  222 + * Set the backgroundImageView `image` with an `url`, placeholder and custom options.
  223 + *
  224 + * The download is asynchronous and cached.
  225 + *
  226 + * @param url The url for the image.
  227 + * @param placeholder The image to be set initially, until the image request finishes.
  228 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  229 + * @param completedBlock A block called when operation has been completed. This block has no return value
  230 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  231 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  232 + * indicating if the image was retrieved from the local cache or from the network.
  233 + * The fourth parameter is the original image url.
  234 + */
  235 +- (void)HH_setBackgroundImageWithURL:(nullable NSURL *)url
  236 + forState:(UIControlState)state
  237 + placeholderImage:(nullable UIImage *)placeholder
  238 + options:(HHWebImageOptions)options
  239 + completed:(nullable HHExternalCompletionBlock)completedBlock;
  240 +
  241 +#pragma mark - Cancel
  242 +
  243 +/**
  244 + * Cancel the current image download
  245 + */
  246 +- (void)HH_cancelImageLoadForState:(UIControlState)state;
  247 +
  248 +/**
  249 + * Cancel the current backgroundImage download
  250 + */
  251 +- (void)HH_cancelBackgroundImageLoadForState:(UIControlState)state;
  252 +
  253 +@end
  254 +
  255 +#endif
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +
  11 +@interface UIImage (hhForceDecode)
  12 +
  13 ++ (nullable UIImage *)decodedImageWithImage:(nullable UIImage *)image;
  14 +
  15 ++ (nullable UIImage *)decodedAndScaledDownImageWithImage:(nullable UIImage *)image;
  16 +
  17 +@end
  1 +/*
  2 + * This file is part of the HHWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + * (c) Laurin Brandner
  5 + *
  6 + * For the full copyright and license information, please view the LICENSE
  7 + * file that was distributed with this source code.
  8 + */
  9 +
  10 +#import "HHWebImageCompat.h"
  11 +
  12 +@interface UIImage (hhGIF)
  13 +
  14 +/**
  15 + * Creates an animated UIImage from an NSData.
  16 + * For static GIF, will create an UIImage with `images` array set to nil. For animated GIF, will create an UIImage with valid `images` array.
  17 + */
  18 ++ (UIImage *)HH_animatedGIFWithData:(NSData *)data;
  19 +
  20 +/**
  21 + * Checks if an UIImage instance is a GIF. Will use the `images` array.
  22 + */
  23 +- (BOOL)isGIF;
  24 +
  25 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +#import "NSData+hhImageContentType.h"
  11 +
  12 +@interface UIImage (hhMultiFormat)
  13 +
  14 +/**
  15 + * UIKit:
  16 + * For static image format, this value is always 0.
  17 + * For animated image format, 0 means infinite looping.
  18 + * Note that because of the limitations of categories this property can get out of sync if you create another instance with CGImage or other methods.
  19 + * AppKit:
  20 + * NSImage currently only support animated via GIF imageRep unlike UIImage.
  21 + * The getter of this property will get the loop count from GIF imageRep
  22 + * The setter of this property will set the loop count from GIF imageRep
  23 + */
  24 +@property (nonatomic, assign) NSUInteger HH_imageLoopCount;
  25 +
  26 ++ (nullable UIImage *)HH_imageWithData:(nullable NSData *)data;
  27 +- (nullable NSData *)HH_imageData;
  28 +- (nullable NSData *)HH_imageDataAsFormat:(HHImageFormat)imageFormat;
  29 +
  30 +@end
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +
  11 +#if HH_UIKIT
  12 +
  13 +#import "HHWebImageManager.h"
  14 +
  15 +/**
  16 + * Integrates HHWebImage async downloading and caching of remote images with UIImageView for highlighted state.
  17 + */
  18 +@interface UIImageView (hhHighlightedWebCache)
  19 +
  20 +/**
  21 + * Set the imageView `highlightedImage` with an `url`.
  22 + *
  23 + * The download is asynchronous and cached.
  24 + *
  25 + * @param url The url for the image.
  26 + */
  27 +- (void)HH_setHighlightedImageWithURL:(nullable NSURL *)url NS_REFINED_FOR_SWIFT;
  28 +
  29 +/**
  30 + * Set the imageView `highlightedImage` with an `url` and custom options.
  31 + *
  32 + * The download is asynchronous and cached.
  33 + *
  34 + * @param url The url for the image.
  35 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  36 + */
  37 +- (void)HH_setHighlightedImageWithURL:(nullable NSURL *)url
  38 + options:(HHWebImageOptions)options NS_REFINED_FOR_SWIFT;
  39 +
  40 +/**
  41 + * Set the imageView `highlightedImage` with an `url`.
  42 + *
  43 + * The download is asynchronous and cached.
  44 + *
  45 + * @param url The url for the image.
  46 + * @param completedBlock A block called when operation has been completed. This block has no return value
  47 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  48 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  49 + * indicating if the image was retrieved from the local cache or from the network.
  50 + * The fourth parameter is the original image url.
  51 + */
  52 +- (void)HH_setHighlightedImageWithURL:(nullable NSURL *)url
  53 + completed:(nullable HHExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
  54 +
  55 +/**
  56 + * Set the imageView `highlightedImage` with an `url` and custom options.
  57 + *
  58 + * The download is asynchronous and cached.
  59 + *
  60 + * @param url The url for the image.
  61 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  62 + * @param completedBlock A block called when operation has been completed. This block has no return value
  63 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  64 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  65 + * indicating if the image was retrieved from the local cache or from the network.
  66 + * The fourth parameter is the original image url.
  67 + */
  68 +- (void)HH_setHighlightedImageWithURL:(nullable NSURL *)url
  69 + options:(HHWebImageOptions)options
  70 + completed:(nullable HHExternalCompletionBlock)completedBlock;
  71 +
  72 +/**
  73 + * Set the imageView `highlightedImage` with an `url` and custom options.
  74 + *
  75 + * The download is asynchronous and cached.
  76 + *
  77 + * @param url The url for the image.
  78 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  79 + * @param progressBlock A block called while image is downloading
  80 + * @note the progress block is executed on a background queue
  81 + * @param completedBlock A block called when operation has been completed. This block has no return value
  82 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  83 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  84 + * indicating if the image was retrieved from the local cache or from the network.
  85 + * The fourth parameter is the original image url.
  86 + */
  87 +- (void)HH_setHighlightedImageWithURL:(nullable NSURL *)url
  88 + options:(HHWebImageOptions)options
  89 + progress:(nullable HHWebImageDownloaderProgressBlock)progressBlock
  90 + completed:(nullable HHExternalCompletionBlock)completedBlock;
  91 +
  92 +@end
  93 +
  94 +#endif
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +
  11 +#if HH_UIKIT || HH_MAC
  12 +
  13 +#import "HHWebImageManager.h"
  14 +
  15 +
  16 +@interface UIImageView (hhWebCache)
  17 +
  18 +/**
  19 + * Set the imageView `image` with an `url`.
  20 + *
  21 + * The download is asynchronous and cached.
  22 + *
  23 + * @param url The url for the image.
  24 + */
  25 +- (void)HH_setImageWithURL:(nullable NSURL *)url NS_REFINED_FOR_SWIFT;
  26 +
  27 +/**
  28 + * Set the imageView `image` with an `url` and a placeholder.
  29 + *
  30 + * The download is asynchronous and cached.
  31 + *
  32 + * @param url The url for the image.
  33 + * @param placeholder The image to be set initially, until the image request finishes.
  34 + * @see HH_setImageWithURL:placeholderImage:options:
  35 + */
  36 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  37 + placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
  38 +
  39 +/**
  40 + * Set the imageView `image` with an `url`, placeholder and custom options.
  41 + *
  42 + * The download is asynchronous and cached.
  43 + *
  44 + * @param url The url for the image.
  45 + * @param placeholder The image to be set initially, until the image request finishes.
  46 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  47 + */
  48 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  49 + placeholderImage:(nullable UIImage *)placeholder
  50 + options:(HHWebImageOptions)options NS_REFINED_FOR_SWIFT;
  51 +
  52 +/**
  53 + * Set the imageView `image` with an `url`.
  54 + *
  55 + * The download is asynchronous and cached.
  56 + *
  57 + * @param url The url for the image.
  58 + * @param completedBlock A block called when operation has been completed. This block has no return value
  59 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  60 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  61 + * indicating if the image was retrieved from the local cache or from the network.
  62 + * The fourth parameter is the original image url.
  63 + */
  64 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  65 + completed:(nullable HHExternalCompletionBlock)completedBlock;
  66 +
  67 +/**
  68 + * Set the imageView `image` with an `url`, placeholder.
  69 + *
  70 + * The download is asynchronous and cached.
  71 + *
  72 + * @param url The url for the image.
  73 + * @param placeholder The image to be set initially, until the image request finishes.
  74 + * @param completedBlock A block called when operation has been completed. This block has no return value
  75 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  76 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  77 + * indicating if the image was retrieved from the local cache or from the network.
  78 + * The fourth parameter is the original image url.
  79 + */
  80 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  81 + placeholderImage:(nullable UIImage *)placeholder
  82 + completed:(nullable HHExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
  83 +
  84 +/**
  85 + * Set the imageView `image` with an `url`, placeholder and custom options.
  86 + *
  87 + * The download is asynchronous and cached.
  88 + *
  89 + * @param url The url for the image.
  90 + * @param placeholder The image to be set initially, until the image request finishes.
  91 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  92 + * @param completedBlock A block called when operation has been completed. This block has no return value
  93 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  94 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  95 + * indicating if the image was retrieved from the local cache or from the network.
  96 + * The fourth parameter is the original image url.
  97 + */
  98 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  99 + placeholderImage:(nullable UIImage *)placeholder
  100 + options:(HHWebImageOptions)options
  101 + completed:(nullable HHExternalCompletionBlock)completedBlock;
  102 +
  103 +/**
  104 + * Set the imageView `image` with an `url`, placeholder and custom options.
  105 + *
  106 + * The download is asynchronous and cached.
  107 + *
  108 + * @param url The url for the image.
  109 + * @param placeholder The image to be set initially, until the image request finishes.
  110 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  111 + * @param progressBlock A block called while image is downloading
  112 + * @note the progress block is executed on a background queue
  113 + * @param completedBlock A block called when operation has been completed. This block has no return value
  114 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  115 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  116 + * indicating if the image was retrieved from the local cache or from the network.
  117 + * The fourth parameter is the original image url.
  118 + */
  119 +- (void)HH_setImageWithURL:(nullable NSURL *)url
  120 + placeholderImage:(nullable UIImage *)placeholder
  121 + options:(HHWebImageOptions)options
  122 + progress:(nullable HHWebImageDownloaderProgressBlock)progressBlock
  123 + completed:(nullable HHExternalCompletionBlock)completedBlock;
  124 +
  125 +/**
  126 + * Set the imageView `image` with an `url` and custom options. The placeholder image is from previous cached image and will use the provided one instead if the query failed.
  127 + * This method was designed to ensure that placeholder and query cache process happened in the same runloop to avoid flashing on cell during two `setImage:` call. But it's really misunderstanding and deprecated.
  128 + * This can be done by using `HH_setImageWithURL:` with `HHWebImageQueryDiskSync`. But take care that if the memory cache missed, query disk cache synchronously may reduce the frame rate
  129 + *
  130 + * The download is asynchronous and cached.
  131 + *
  132 + * @param url The url for the image.
  133 + * @param placeholder The image to be set initially, until the image request finishes.
  134 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  135 + * @param progressBlock A block called while image is downloading
  136 + * @note the progress block is executed on a background queue
  137 + * @param completedBlock A block called when operation has been completed. This block has no return value
  138 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  139 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  140 + * indicating if the image was retrieved from the local cache or from the network.
  141 + * The fourth parameter is the original image url.
  142 + * @deprecated consider using `HHWebImageQueryDiskSync` options with `HH_setImageWithURL:` instead
  143 + */
  144 +- (void)HH_setImageWithPreviousCachedImageWithURL:(nullable NSURL *)url
  145 + placeholderImage:(nullable UIImage *)placeholder
  146 + options:(HHWebImageOptions)options
  147 + progress:(nullable HHWebImageDownloaderProgressBlock)progressBlock
  148 + completed:(nullable HHExternalCompletionBlock)completedBlock __deprecated_msg("This method is misunderstanding and deprecated, consider using `HHWebImageQueryDiskSync` options with `HH_setImageWithURL:` instead");
  149 +
  150 +#if HH_UIKIT
  151 +
  152 +#pragma mark - Animation of multiple images
  153 +
  154 +/**
  155 + * Download an array of images and starts them in an animation loop
  156 + *
  157 + * @param arrayOfURLs An array of NSURL
  158 + */
  159 +- (void)HH_setAnimationImagesWithURLs:(nonnull NSArray<NSURL *> *)arrayOfURLs;
  160 +
  161 +- (void)HH_cancelCurrentAnimationImagesLoad;
  162 +
  163 +#endif
  164 +
  165 +@end
  166 +
  167 +#endif
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +
  11 +#if HH_UIKIT || HH_MAC
  12 +
  13 +#import "HHWebImageManager.h"
  14 +#import "HHWebImageTransition.h"
  15 +
  16 +/**
  17 + A Dispatch group to maintain setImageBlock and completionBlock. This key should be used only internally and may be changed in the future. (dispatch_group_t)
  18 + */
  19 +FOUNDATION_EXPORT NSString * _Nonnull const HHWebImageInternalSetImageGroupKey;
  20 +/**
  21 + A HHWebImageManager instance to control the image download and cache process using in UIImageView+WebCache category and likes. If not provided, use the shared manager (HHWebImageManager)
  22 + */
  23 +FOUNDATION_EXPORT NSString * _Nonnull const HHWebImageExternalCustomManagerKey;
  24 +/**
  25 + The value specify that the image progress unit count cannot be determined because the progressBlock is not been called.
  26 + */
  27 +FOUNDATION_EXPORT const int64_t HHWebImageProgressUnitCountUnknown; /* 1LL */
  28 +
  29 +typedef void(^HHSetImageBlock)(UIImage * _Nullable image, NSData * _Nullable imageData);
  30 +
  31 +@interface UIView (hhWebCache)
  32 +
  33 +/**
  34 + * Get the current image URL.
  35 + *
  36 + * @note Note that because of the limitations of categories this property can get out of sync if you use setImage: directly.
  37 + */
  38 +- (nullable NSURL *)HH_imageURL;
  39 +
  40 +/**
  41 + * The current image loading progress associated to the view. The unit count is the received size and excepted size of download.
  42 + * The `totalUnitCount` and `completedUnitCount` will be reset to 0 after a new image loading start (change from current queue). And they will be set to `HHWebImageProgressUnitCountUnknown` if the progressBlock not been called but the image loading success to mark the progress finished (change from main queue).
  43 + * @note You can use Key-Value Observing on the progress, but you should take care that the change to progress is from a background queue during download(the same as progressBlock). If you want to using KVO and update the UI, make sure to dispatch on the main queue. And it's recommand to use some KVO libs like KVOController because it's more safe and easy to use.
  44 + * @note The getter will create a progress instance if the value is nil. You can also set a custom progress instance and let it been updated during image loading
  45 + * @note Note that because of the limitations of categories this property can get out of sync if you update the progress directly.
  46 + */
  47 +@property (nonatomic, strong, null_resettable) NSProgress *HH_imageProgress;
  48 +
  49 +/**
  50 + * Set the imageView `image` with an `url` and optionally a placeholder image.
  51 + *
  52 + * The download is asynchronous and cached.
  53 + *
  54 + * @param url The url for the image.
  55 + * @param placeholder The image to be set initially, until the image request finishes.
  56 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  57 + * @param operationKey A string to be used as the operation key. If nil, will use the class name
  58 + * @param setImageBlock Block used for custom set image code
  59 + * @param progressBlock A block called while image is downloading
  60 + * @note the progress block is executed on a background queue
  61 + * @param completedBlock A block called when operation has been completed. This block has no return value
  62 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  63 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  64 + * indicating if the image was retrieved from the local cache or from the network.
  65 + * The fourth parameter is the original image url.
  66 + */
  67 +- (void)HH_internalSetImageWithURL:(nullable NSURL *)url
  68 + placeholderImage:(nullable UIImage *)placeholder
  69 + options:(HHWebImageOptions)options
  70 + operationKey:(nullable NSString *)operationKey
  71 + setImageBlock:(nullable HHSetImageBlock)setImageBlock
  72 + progress:(nullable HHWebImageDownloaderProgressBlock)progressBlock
  73 + completed:(nullable HHExternalCompletionBlock)completedBlock;
  74 +
  75 +/**
  76 + * Set the imageView `image` with an `url` and optionally a placeholder image.
  77 + *
  78 + * The download is asynchronous and cached.
  79 + *
  80 + * @param url The url for the image.
  81 + * @param placeholder The image to be set initially, until the image request finishes.
  82 + * @param options The options to use when downloading the image. @see HHWebImageOptions for the possible values.
  83 + * @param operationKey A string to be used as the operation key. If nil, will use the class name
  84 + * @param setImageBlock Block used for custom set image code
  85 + * @param progressBlock A block called while image is downloading
  86 + * @note the progress block is executed on a background queue
  87 + * @param completedBlock A block called when operation has been completed. This block has no return value
  88 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  89 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  90 + * indicating if the image was retrieved from the local cache or from the network.
  91 + * The fourth parameter is the original image url.
  92 + * @param context A context with extra information to perform specify changes or processes.
  93 + */
  94 +- (void)HH_internalSetImageWithURL:(nullable NSURL *)url
  95 + placeholderImage:(nullable UIImage *)placeholder
  96 + options:(HHWebImageOptions)options
  97 + operationKey:(nullable NSString *)operationKey
  98 + setImageBlock:(nullable HHSetImageBlock)setImageBlock
  99 + progress:(nullable HHWebImageDownloaderProgressBlock)progressBlock
  100 + completed:(nullable HHExternalCompletionBlock)completedBlock
  101 + context:(nullable NSDictionary<NSString *, id> *)context;
  102 +
  103 +/**
  104 + * Cancel the current image load
  105 + */
  106 +- (void)HH_cancelCurrentImageLoad;
  107 +
  108 +#pragma mark - Image Transition
  109 +
  110 +/**
  111 + The image transition when image load finished. See `HHWebImageTransition`.
  112 + If you specify nil, do not do transition. Defautls to nil.
  113 + */
  114 +@property (nonatomic, strong, nullable) HHWebImageTransition *HH_imageTransition;
  115 +
  116 +#if HH_UIKIT
  117 +
  118 +#pragma mark - Activity indicator
  119 +
  120 +/**
  121 + * Show activity UIActivityIndicatorView
  122 + */
  123 +- (void)HH_setShowActivityIndicatorView:(BOOL)show;
  124 +
  125 +/**
  126 + * set desired UIActivityIndicatorViewStyle
  127 + *
  128 + * @param style The style of the UIActivityIndicatorView
  129 + */
  130 +- (void)HH_setIndicatorStyle:(UIActivityIndicatorViewStyle)style;
  131 +
  132 +- (BOOL)HH_showActivityIndicatorView;
  133 +- (void)HH_addActivityIndicator;
  134 +- (void)HH_removeActivityIndicator;
  135 +
  136 +#endif
  137 +
  138 +@end
  139 +
  140 +#endif
  1 +/*
  2 + * This file is part of the HHWebImage 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 +
  9 +#import "HHWebImageCompat.h"
  10 +
  11 +#if HH_UIKIT || HH_MAC
  12 +
  13 +#import "HHWebImageManager.h"
  14 +
  15 +// These methods are used to support canceling for UIView image loading, it's designed to be used internal but not external.
  16 +// All the stored operations are weak, so it will be dalloced after image loading finished. If you need to store operations, use your own class to keep a strong reference for them.
  17 +@interface UIView (hhWebCacheOperation)
  18 +
  19 +/**
  20 + * Set the image load operation (storage in a UIView based weak map table)
  21 + *
  22 + * @param operation the operation
  23 + * @param key key for storing the operation
  24 + */
  25 +- (void)HH_setImageLoadOperation:(nullable id<HHWebImageOperation>)operation forKey:(nullable NSString *)key;
  26 +
  27 +/**
  28 + * Cancel all operations for the current UIView and key
  29 + *
  30 + * @param key key for identifying the operations
  31 + */
  32 +- (void)HH_cancelImageLoadOperationWithKey:(nullable NSString *)key;
  33 +
  34 +/**
  35 + * Just remove the operations corresponding to the current UIView and key without cancelling them
  36 + *
  37 + * @param key key for identifying the operations
  38 + */
  39 +- (void)HH_removeImageLoadOperationWithKey:(nullable NSString *)key;
  40 +
  41 +@end
  42 +
  43 +#endif