SDWebImagePrefetcher.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import <Foundation/Foundation.h>
  9. #import "SDWebImageManager.h"
  10. @class SDWebImagePrefetcher;
  11. @protocol SDWebImagePrefetcherDelegate <NSObject>
  12. @optional
  13. /**
  14. * Called when an image was prefetched.
  15. *
  16. * @param imagePrefetcher The current image prefetcher
  17. * @param imageURL The image url that was prefetched
  18. * @param finishedCount The total number of images that were prefetched (successful or not)
  19. * @param totalCount The total number of images that were to be prefetched
  20. */
  21. - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
  22. /**
  23. * Called when all images are prefetched.
  24. * @param imagePrefetcher The current image prefetcher
  25. * @param totalCount The total number of images that were prefetched (whether successful or not)
  26. * @param skippedCount The total number of images that were skipped
  27. */
  28. - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
  29. @end
  30. typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls);
  31. typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls);
  32. /**
  33. * Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
  34. */
  35. @interface SDWebImagePrefetcher : NSObject
  36. /**
  37. * The web image manager
  38. */
  39. @property (strong, nonatomic, readonly) SDWebImageManager *manager;
  40. /**
  41. * Maximum number of URLs to prefetch at the same time. Defaults to 3.
  42. */
  43. @property (nonatomic, assign) NSUInteger maxConcurrentDownloads;
  44. /**
  45. * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority.
  46. */
  47. @property (nonatomic, assign) SDWebImageOptions options;
  48. @property (weak, nonatomic) id <SDWebImagePrefetcherDelegate> delegate;
  49. /**
  50. * Return the global image prefetcher instance.
  51. */
  52. + (SDWebImagePrefetcher *)sharedImagePrefetcher;
  53. /**
  54. * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
  55. * currently one image is downloaded at a time,
  56. * and skips images for failed downloads and proceed to the next image in the list
  57. *
  58. * @param urls list of URLs to prefetch
  59. */
  60. - (void)prefetchURLs:(NSArray *)urls;
  61. /**
  62. * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
  63. * currently one image is downloaded at a time,
  64. * and skips images for failed downloads and proceed to the next image in the list
  65. *
  66. * @param urls list of URLs to prefetch
  67. * @param progressBlock block to be called when progress updates;
  68. * first parameter is the number of completed (successful or not) requests,
  69. * second parameter is the total number of images originally requested to be prefetched
  70. * @param completionBlock block to be called when prefetching is completed
  71. * first param is the number of completed (successful or not) requests,
  72. * second parameter is the number of skipped requests
  73. */
  74. - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock;
  75. /**
  76. * Remove and cancel queued list
  77. */
  78. - (void)cancelPrefetching;
  79. @end