1 // Copyright 2015-present 650 Industries. All rights reserved. 2 3 #import <Foundation/Foundation.h> 4 #import "EXResourceLoader.h" 5 6 @class EXAbstractLoader; 7 @class EXAppFetcher; 8 @class EXManifestsManifest; 9 10 NS_ASSUME_NONNULL_BEGIN 11 12 @protocol EXAppFetcherDelegate <NSObject> 13 14 /** 15 * If the delegate guessed incorrectly about which subclass of AppFetcher to use, 16 * this method should be called so that the new AppFetcher can be set up properly. 17 * 18 * Use retainingCurrent:YES only if the current (calling) AppFetcher is still doing work 19 * (e.g. fetching an update in the background) and should not be immediately deallocated. 20 */ 21 - (void)appFetcher:(EXAppFetcher *)appFetcher didSwitchToAppFetcher:(EXAppFetcher *)newAppFetcher retainingCurrent:(BOOL)shouldRetain; 22 23 - (void)appFetcher:(EXAppFetcher *)appFetcher didLoadOptimisticManifest:(EXManifestsManifest *)manifest; 24 - (void)appFetcher:(EXAppFetcher *)appFetcher didFinishLoadingManifest:(EXManifestsManifest *)manifest bundle:(NSData *)bundle; 25 - (void)appFetcher:(EXAppFetcher *)appFetcher didFailWithError:(NSError *)error; 26 27 @end 28 29 @protocol EXAppFetcherDataSource <NSObject> 30 31 - (NSString *)bundleResourceNameForAppFetcher:(EXAppFetcher *)appFetcher withManifest:(EXManifestsManifest *)manifest; 32 - (BOOL)appFetcherShouldInvalidateBundleCache:(EXAppFetcher *)appFetcher; 33 34 @end 35 36 @protocol EXAppFetcherCacheDataSource <NSObject> 37 38 - (BOOL)isCacheUpToDateWithAppFetcher:(EXAppFetcher *)appFetcher; 39 40 @end 41 42 @interface EXAppFetcher : NSObject 43 44 @property (nonatomic, readonly) EXManifestsManifest * _Nullable manifest; 45 @property (nonatomic, readonly) NSData * _Nullable bundle; 46 @property (nonatomic, readonly) NSError * _Nullable error; 47 48 @property (nonatomic, weak) id<EXAppFetcherDelegate> delegate; 49 @property (nonatomic, weak) id<EXAppFetcherDataSource> dataSource; 50 @property (nonatomic, weak) id<EXAppFetcherCacheDataSource> cacheDataSource; 51 52 - (instancetype)initWithAppLoader:(EXAbstractLoader *)appLoader; 53 - (void)start; 54 55 - (void)fetchJSBundleWithManifest:(EXManifestsManifest *)manifest 56 cacheBehavior:(EXCachedResourceBehavior)cacheBehavior 57 timeoutInterval:(NSTimeInterval)timeoutInterval 58 progress:(void (^ _Nullable )(EXLoadingProgress *))progressBlock 59 success:(void (^)(NSData *))successBlock 60 error:(void (^)(NSError *))errorBlock; 61 62 + (EXCachedResourceBehavior)cacheBehaviorForJSWithManifest:(EXManifestsManifest *)manifest; 63 64 @end 65 66 NS_ASSUME_NONNULL_END 67