Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Using native-interface preference from config.xml to check, if we are…
Browse files Browse the repository at this point in the history
… allowed to download the update from the server.

#45
  • Loading branch information
nikDemyankov committed Feb 29, 2016
1 parent 101ce32 commit d5cecf4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/ios/HCPPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions src/ios/Updater/HCPUpdateLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions src/ios/Updater/HCPUpdateLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,7 +46,9 @@ - (BOOL)downloadUpdateWithConfigUrl:(NSURL *)configUrl currentVersion:(NSString
}

*error = nil;
id<HCPWorker> task = [[HCPUpdateLoaderWorker alloc] initWithConfigUrl:configUrl currentVersion:currentVersion];
id<HCPWorker> task = [[HCPUpdateLoaderWorker alloc] initWithConfigUrl:configUrl
currentWebVersion:currentWebVersion
nativeInterfaceVersion:currentNativeVersion];
[self executeTask:task];

return YES;
Expand Down
2 changes: 1 addition & 1 deletion src/ios/Updater/HCPUpdateLoaderWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions src/ios/Updater/HCPUpdateLoaderWorker.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#import "HCPUpdateLoaderWorker.h"
#import "NSJSONSerialization+HCPExtension.h"
#import "NSBundle+HCPExtension.h"
#import "HCPManifestDiff.h"
#import "HCPManifestFile.h"
#import "HCPApplicationConfigStorage.h"
Expand All @@ -20,6 +19,7 @@
@interface HCPUpdateLoaderWorker() {
NSURL *_configURL;
HCPFilesStructure *_pluginFiles;
NSUInteger _nativeInterfaceVersion;

id<HCPConfigFileStorage> _appConfigStorage;
id<HCPConfigFileStorage> _manifestStorage;
Expand All @@ -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];
}
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit d5cecf4

Please sign in to comment.