From d5cecf44b6ca86730ae5a76cf051c33c516d0416 Mon Sep 17 00:00:00 2001 From: Nikolay Demyankov Date: Mon, 29 Feb 2016 12:00:18 +0100 Subject: [PATCH] Using native-interface preference from config.xml to check, if we are allowed to download the update from the server. https://github.com/nordnet/cordova-hot-code-push/issues/45 --- src/ios/HCPPlugin.m | 3 ++- src/ios/Updater/HCPUpdateLoader.h | 10 ++++++---- src/ios/Updater/HCPUpdateLoader.m | 6 ++++-- src/ios/Updater/HCPUpdateLoaderWorker.h | 2 +- src/ios/Updater/HCPUpdateLoaderWorker.m | 9 +++++---- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/ios/HCPPlugin.m b/src/ios/HCPPlugin.m index d40a574a..7d79aa59 100644 --- a/src/ios/HCPPlugin.m +++ b/src/ios/HCPPlugin.m @@ -164,7 +164,8 @@ - (BOOL)_fetchUpdate:(NSString *)callbackId { NSError *error = nil; [[HCPUpdateLoader sharedInstance] downloadUpdateWithConfigUrl:_pluginXmlConfig.configUrl - currentVersion:_pluginInternalPrefs.currentReleaseVersionName + currentWebVersion:_pluginInternalPrefs.currentReleaseVersionName + currentNativeVersion:_pluginXmlConfig.nativeInterfaceVersion error:&error]; if (error) { if (callbackId) { diff --git a/src/ios/Updater/HCPUpdateLoader.h b/src/ios/Updater/HCPUpdateLoader.h index 8923a80c..4ab7d52c 100644 --- a/src/ios/Updater/HCPUpdateLoader.h +++ b/src/ios/Updater/HCPUpdateLoader.h @@ -29,12 +29,14 @@ /** * Add update download task to queue. It will be executed as fast as possible. * - * @param configUrl url to the application config on the server - * @param currentVersion current working version of the web content + * @param configUrl url to the application config on the server + * @param currentWebVersion current working version of the web content + * @param currentNativeVersion current native version of the app + * @param error error object reference; filled with data when we failed to launch the update task * - * @return id of the created worker + * @return YES if download task is launched; NO - otherwise */ -- (BOOL)downloadUpdateWithConfigUrl:(NSURL *)configUrl currentVersion:(NSString *)currentVersion error:(NSError **)error; +- (BOOL)downloadUpdateWithConfigUrl:(NSURL *)configUrl currentWebVersion:(NSString *)currentWebVersion currentNativeVersion:(NSUInteger)currentNativeVersion error:(NSError **)error; /** * Flag to check if we are doing any downloads at the moment. diff --git a/src/ios/Updater/HCPUpdateLoader.m b/src/ios/Updater/HCPUpdateLoader.m index d32723e9..148dc30d 100644 --- a/src/ios/Updater/HCPUpdateLoader.m +++ b/src/ios/Updater/HCPUpdateLoader.m @@ -33,7 +33,7 @@ - (BOOL)isDownloadInProgress { return _isExecuting; } -- (BOOL)downloadUpdateWithConfigUrl:(NSURL *)configUrl currentVersion:(NSString *)currentVersion error:(NSError **)error { +- (BOOL)downloadUpdateWithConfigUrl:(NSURL *)configUrl currentWebVersion:(NSString *)currentWebVersion currentNativeVersion:(NSUInteger)currentNativeVersion error:(NSError **)error { if (_isExecuting) { *error = [NSError errorWithCode:kHCPDownloadAlreadyInProgressErrorCode description:@"Download already in progress. Please, wait for it to finish."]; return NO; @@ -46,7 +46,9 @@ - (BOOL)downloadUpdateWithConfigUrl:(NSURL *)configUrl currentVersion:(NSString } *error = nil; - id task = [[HCPUpdateLoaderWorker alloc] initWithConfigUrl:configUrl currentVersion:currentVersion]; + id task = [[HCPUpdateLoaderWorker alloc] initWithConfigUrl:configUrl + currentWebVersion:currentWebVersion + nativeInterfaceVersion:currentNativeVersion]; [self executeTask:task]; return YES; diff --git a/src/ios/Updater/HCPUpdateLoaderWorker.h b/src/ios/Updater/HCPUpdateLoaderWorker.h index 27b820e8..bf9e4228 100644 --- a/src/ios/Updater/HCPUpdateLoaderWorker.h +++ b/src/ios/Updater/HCPUpdateLoaderWorker.h @@ -24,6 +24,6 @@ * @return instance of the object * @see HCPFilesStructure */ -- (instancetype)initWithConfigUrl:(NSURL *)configURL currentVersion:(NSString *)currentVersion; +- (instancetype)initWithConfigUrl:(NSURL *)configURL currentWebVersion:(NSString *)currentWebVersion nativeInterfaceVersion:(NSUInteger)currentNativeVersion; @end diff --git a/src/ios/Updater/HCPUpdateLoaderWorker.m b/src/ios/Updater/HCPUpdateLoaderWorker.m index 18ea2a80..bb8ccc01 100644 --- a/src/ios/Updater/HCPUpdateLoaderWorker.m +++ b/src/ios/Updater/HCPUpdateLoaderWorker.m @@ -6,7 +6,6 @@ #import "HCPUpdateLoaderWorker.h" #import "NSJSONSerialization+HCPExtension.h" -#import "NSBundle+HCPExtension.h" #import "HCPManifestDiff.h" #import "HCPManifestFile.h" #import "HCPApplicationConfigStorage.h" @@ -20,6 +19,7 @@ @interface HCPUpdateLoaderWorker() { NSURL *_configURL; HCPFilesStructure *_pluginFiles; + NSUInteger _nativeInterfaceVersion; id _appConfigStorage; id _manifestStorage; @@ -38,12 +38,13 @@ @implementation HCPUpdateLoaderWorker #pragma mark Public API -- (instancetype)initWithConfigUrl:(NSURL *)configURL currentVersion:(NSString *)currentVersion { +- (instancetype)initWithConfigUrl:(NSURL *)configURL currentWebVersion:(NSString *)currentWebVersion nativeInterfaceVersion:(NSUInteger)currentNativeVersion { self = [super init]; if (self) { _configURL = configURL; + _nativeInterfaceVersion = currentNativeVersion; _workerId = [self generateWorkerId]; - _pluginFiles = [[HCPFilesStructure alloc] initWithReleaseVersion:currentVersion]; + _pluginFiles = [[HCPFilesStructure alloc] initWithReleaseVersion:currentWebVersion]; _appConfigStorage = [[HCPApplicationConfigStorage alloc] initWithFileStructure:_pluginFiles]; _manifestStorage = [[HCPContentManifestStorage alloc] initWithFileStructure:_pluginFiles]; } @@ -85,7 +86,7 @@ - (void)runWithComplitionBlock:(void (^)(void))updateLoaderComplitionBlock { } // check if current native version supports new content - if (newAppConfig.contentConfig.minimumNativeVersion > [NSBundle applicationBuildVersion]) { + if (newAppConfig.contentConfig.minimumNativeVersion > _nativeInterfaceVersion) { [self notifyWithError:[NSError errorWithCode:kHCPApplicationBuildVersionTooLowErrorCode description:@"Application build version is too low for this update"] applicationConfig:newAppConfig];