EMSDWebImagePrefetcher.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "EMSDWebImageManager.h"
  10. @class EMSDWebImagePrefetcher;
  11. @protocol EMSDWebImagePrefetcherDelegate <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:(EMSDWebImagePrefetcher *)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:(EMSDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
  29. @end
  30. typedef void(^EMSDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls);
  31. typedef void(^EMSDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls);
  32. /**
  33. * Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
  34. */
  35. @interface EMSDWebImagePrefetcher : NSObject
  36. /**
  37. * The web image manager
  38. */
  39. @property (strong, nonatomic, readonly) EMSDWebImageManager *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. * EMSDWebImageOptions for prefetcher. Defaults to EMSDWebImageLowPriority.
  46. */
  47. @property (nonatomic, assign) EMSDWebImageOptions options;
  48. @property (weak, nonatomic) id <EMSDWebImagePrefetcherDelegate> delegate;
  49. /**
  50. * Return the global image prefetcher instance.
  51. */
  52. + (EMSDWebImagePrefetcher *)sharedImagePrefetcher;
  53. /**
  54. * Assign list of URLs to let EMSDWebImagePrefetcher 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 EMSDWebImagePrefetcher 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:(EMSDWebImagePrefetcherProgressBlock)progressBlock completed:(EMSDWebImagePrefetcherCompletionBlock)completionBlock;
  75. /**
  76. * Remove and cancel queued list
  77. */
  78. - (void)cancelPrefetching;
  79. @end