1 // Copyright 2015-present 650 Industries. All rights reserved.
2 
3 #import <Foundation/Foundation.h>
4 
5 NS_ASSUME_NONNULL_BEGIN
6 
7 /**
8  * This is the versioned protocol for EXCachedResource, this also defines some
9  * of the types used when interacting with EXCachedResource instances. This is
10  * used with the EXCachedResourceManager service to be able to create EXCachedResource
11  * instances in versioned code.
12  *
13  * **Avoid making breaking changes to this and if you do make sure to edit all
14  * versions of this file.**
15  */
16 
17 @interface EXLoadingProgress : NSObject
18 
19 @property (nonatomic, copy) NSString *status;
20 @property (nonatomic, strong) NSNumber *done;
21 @property (nonatomic, strong) NSNumber *total;
22 
23 @end
24 
25 typedef void (^EXCachedResourceSuccessBlock)(NSData *data);
26 typedef void (^EXCachedResourceErrorBlock)(NSError *error);
27 typedef void (^EXCachedResourceProgressBlock)(EXLoadingProgress *progress);
28 
29 typedef enum EXCachedResourceBehavior {
30   // load the resource without using any cache.
31   EXCachedResourceNoCache,
32   // return immediately with cached data if it exists, then try to download the resource and replace the cache in the background.
33   EXCachedResourceUseCacheImmediately,
34   // try to download the resource, but fall back to the cached version if the download fails.
35   EXCachedResourceFallBackToCache,
36   // use a cache if it exists, otherwise fail. (don't download anything)
37   EXCachedResourceOnlyCache,
38 } EXCachedResourceBehavior;
39 
40 @protocol EXResourceLoader
41 
42 - (void)loadResourceWithBehavior:(EXCachedResourceBehavior)behavior
43                    progressBlock:(__nullable EXCachedResourceProgressBlock)progressBlock
44                     successBlock:(EXCachedResourceSuccessBlock)successBlock
45                       errorBlock:(EXCachedResourceErrorBlock)errorBlock;
46 
47 @end
48 
49 NS_ASSUME_NONNULL_END
50