From e31be1dfd941e536396c8b904c51bc5bc2534351 Mon Sep 17 00:00:00 2001 From: Nikolay Demyankov Date: Mon, 9 May 2016 15:13:34 +0200 Subject: [PATCH] Handle fetch update options: config-url and request headers. https://github.com/nordnet/cordova-hot-code-push/issues/153 --- src/ios/HCPPlugin.h | 3 --- src/ios/HCPPlugin.m | 24 ++++++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/ios/HCPPlugin.h b/src/ios/HCPPlugin.h index 86aff74a..db10b6da 100644 --- a/src/ios/HCPPlugin.h +++ b/src/ios/HCPPlugin.h @@ -57,7 +57,4 @@ */ - (void)jsIsUpdateAvailableForInstallation:(CDVInvokedUrlCommand *)command; - -@property (nonatomic, retain) NSDictionary* headers; - @end diff --git a/src/ios/HCPPlugin.m b/src/ios/HCPPlugin.m index b6d44d34..1ba079ce 100644 --- a/src/ios/HCPPlugin.m +++ b/src/ios/HCPPlugin.m @@ -22,6 +22,7 @@ #import "HCPAssetsFolderHelper.h" #import "NSError+HCPExtension.h" #import "HCPCleanupHelper.h" +#import "NSDictionary+HCPFetchUpdateOptions.h" @interface HCPPlugin() { HCPFilesStructure *_filesStructure; @@ -160,17 +161,23 @@ - (void)doLocalInit { * * @return YES if download process started; NO otherwise */ -- (BOOL)_fetchUpdate:(NSString *)callbackId { +- (BOOL)_fetchUpdate:(NSString *)callbackId withOptions:(NSDictionary *)options { if (!_isPluginReadyForWork) { return NO; } + NSURL *configURL = [options configURL]; + if (!configURL) { + configURL = _pluginXmlConfig.configUrl; + } + NSDictionary *headers = [options requestHeaders]; + NSError *error = nil; - [[HCPUpdateLoader sharedInstance] downloadUpdateWithConfigUrl:_pluginXmlConfig.configUrl + [[HCPUpdateLoader sharedInstance] downloadUpdateWithConfigUrl:configURL currentWebVersion:_pluginInternalPrefs.currentReleaseVersionName currentNativeVersion:_pluginXmlConfig.nativeInterfaceVersion error:&error - headers:self.headers]; + headers:headers]; if (error) { if (callbackId) { CDVPluginResult *errorResult = [CDVPluginResult pluginResultWithActionName:kHCPUpdateDownloadErrorEvent @@ -465,7 +472,7 @@ - (void)onAssetsInstalledOnExternalStorageEvent:(NSNotification *)notification { if (_pluginXmlConfig.isUpdatesAutoDownloadAllowed && ![HCPUpdateLoader sharedInstance].isDownloadInProgress && ![HCPUpdateInstaller sharedInstance].isInstallationInProgress) { - [self _fetchUpdate:nil]; + [self _fetchUpdate:nil withOptions:nil]; } } @@ -695,7 +702,7 @@ - (void)jsInitPlugin:(CDVInvokedUrlCommand *)command { if (_pluginXmlConfig.isUpdatesAutoDownloadAllowed && ![HCPUpdateLoader sharedInstance].isDownloadInProgress && ![HCPUpdateInstaller sharedInstance].isInstallationInProgress) { - [self _fetchUpdate:nil]; + [self _fetchUpdate:nil withOptions:nil]; } } @@ -718,12 +725,9 @@ - (void)jsFetchUpdate:(CDVInvokedUrlCommand *)command { [self sendPluginNotReadyToWorkMessageForEvent:kHCPUpdateDownloadErrorEvent callbackID:command.callbackId]; } - // headers may be passed as first argument, as a dict - if (command.arguments.count == 1) { - self.headers = command.arguments[0]; - } + NSDictionary *options = command.arguments.count ? command.arguments[0] : nil; - [self _fetchUpdate:command.callbackId]; + [self _fetchUpdate:command.callbackId withOptions:options]; } - (void)jsInstallUpdate:(CDVInvokedUrlCommand *)command {